Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: HelloWorld_IHM02A1 ConcorsoFinal HelloWorld_IHM02A1_mbedOS HelloWorld_IHM02A1-Serialinterpreter ... more
Fork of X_NUCLEO_IHM02A1 by
Motor Control Library
Introduction
Library to handle the X-NUCLEO-IHM02A1 Motor Control Expansion Board based on the the L6470 component.
Daisy-Chain Configuration
The two L6470 components mounted on this board are connected in daisy-chain configuration. This board can be stacked up to four times so that the eight L6470 components will be connected two-by-two in daisy-chain configuration.
Concerning the SSEL pin of the SPI communication, each expansion board must be in one of the following configuration:
SB_23resistor connected only: SSEL on pinA2;SB_7resistor connected only: SSEL on pinD2;SB_8resistor connected only: SSEL on pinD10;SB_9resistor connected only: SSEL on pinD5.
Arduino Connector Compatibility Warning
X-NUCLEO-IHM02A1 is Arduino compatible with one exception: instead of using D13 pin to drive the SPI clock, it uses D3 pin, hence the default configuration for this library is with the SPI clock on D3 pin.
To be fully Arduino compatible the following patch is required:
- to remove the
SB34resistor; - to solder the
SB12resistor.
Alternatively, you can route the Nucleo board’s D13 pin directly to the expansion board’s D3 pin with a wire.
In case you patch your expansion board or route the pin, the SPI clock will be driven on D13 pin rather than on D3 pin, and you have also to initialize the sclk PinName variable with D13 rather than D3.
This patch is known to be required, for example, on the following boards: NUCLEO-F103RB, NUCLEO-F302RB, NUCLEO-F411RE, and NUCLEO-F429ZI.
If you use D13 pin for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to the D13 pin.
Example Applications
Revision 23:cf489f2ab072, committed 2017-03-10
- Comitter:
- Davidroid
- Date:
- Fri Mar 10 15:23:54 2017 +0000
- Parent:
- 22:ba7f4131a5e0
- Child:
- 24:ff67801d7cd7
- Commit message:
- Aligned to ARM mbed coding style.
Changed in this revision
--- a/BSP/XNucleoIhm02a1.cpp Fri Mar 10 11:09:21 2017 +0100
+++ b/BSP/XNucleoIhm02a1.cpp Fri Mar 10 15:23:54 2017 +0000
@@ -97,7 +97,7 @@
/* Initializing the components. */
init_components[0] = init_0;
init_components[1] = init_1;
- if (!Init()) {
+ if (!init()) {
error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
}
}
@@ -139,7 +139,7 @@
/* Initializing the components. */
init_components[0] = init_0;
init_components[1] = init_1;
- if (!Init()) {
+ if (!init()) {
error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/L6470/L6470.cpp Fri Mar 10 15:23:54 2017 +0000
@@ -0,0 +1,1460 @@
+/**
+ ******************************************************************************
+ * @file l6470_class.cpp
+ * @date 01/10/2014 12:00:00
+ * @brief This file provides set of firmware functions to manage the
+ * L6470.
+ ******************************************************************************
+ *
+ * COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+
+/* 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.c
+ Revision: 0
+*/
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "L6470.h"
+
+
+/* Variables -----------------------------------------------------------------*/
+
+/* Number of instantiated devices on an expansion board. */
+uint8_t L6470::number_of_devices = 0;
+
+/* SPI Transmission for Daisy-Chain Configuration. */
+eFlagStatus_t L6470::L6470_DaisyChain_HalfPrepared;
+sL6470_AppCmdPkg_t L6470::L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
+uint8_t L6470::L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
+uint8_t L6470::L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
+
+/**
+ * @brief 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)
+ */
+const sL6470_Register_t L6470::_L6470_Register[L6470REGIDSIZE] = {
+ {0x01 , "ABS_POS", 22, 3, 0x000000}, //!< Current position
+ {0x02 , "EL_POS", 9, 2, 0x000}, //!< Electrical position
+ {0x03 , "MARK", 22, 3, 0x000000}, //!< Mark position
+ {0x04 , "SPEED", 20, 3, 0x0000}, //!< Current speed
+ {0x05 , "ACC", 12, 2, 0x08A}, //!< Acceleration
+ {0x06 , "DEC", 12, 2, 0x08A}, //!< Deceleration
+ {0x07 , "MAX_SPEED", 10, 2, 0x041}, //!< Maximum speed
+ {0x08 , "MIN_SPEED", 13, 2, 0x000}, //!< Minimum speed
+ {0x15 , "FS_SPD", 10, 2, 0x027}, //!< Full-step speed
+ {0x09 , "KVAL_HOLD", 8, 1, 0x29}, //!< Holding KVAL
+ {0x0A , "KVAL_RUN", 8, 1, 0x29}, //!< Constant speed KVAL
+ {0x0B , "KVAL_ACC", 8, 1, 0x29}, //!< Acceleration starting KVAL
+ {0x0C , "KVAL_DEC", 8, 1, 0x29}, //!< Deceleration starting KVAL
+ {0x0D , "INT_SPEED", 14, 2, 0x0408}, //!< Intersect speed
+ {0x0E , "ST_SLP", 8, 1, 0x19}, //!< Start slope
+ {0x0F , "FN_SLP_ACC", 8, 1, 0x29}, //!< Acceleration final slope
+ {0x10 , "FN_SLP_DEC", 8, 1, 0x29}, //!< Deceleration final slope
+ {0x11 , "K_THERM", 4, 1, 0x0}, //!< Thermal compensation factor
+ {0x12 , "ADC_OUT", 5, 1, 0x00}, //!< ADC output, (the reset value is according to startup conditions)
+ {0x13 , "OCD_TH", 4, 1, 0x8}, //!< OCD threshold
+ {0x14 , "STALL_TH", 7, 1, 0x40}, //!< STALL threshold
+ {0x16 , "STEP_MODE", 8, 1, 0x7}, //!< Step mode
+ {0x17 , "ALARM_EN", 8, 1, 0xFF}, //!< Alarm enable
+ {0x18 , "CONFIG", 16, 2, 0x2E88}, //!< IC configuration
+ {0x19 , "STATUS", 16, 2, 0x0000} //!< Status, (the reset value is according to startup conditions)
+};
+
+/**
+ * @brief 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)
+ */
+const sL6470_ApplicationCommand_t L6470::_L6470_ApplicationCommand[L6470APPCMDIDSIZE] = {
+ {"NOP", 0x00, 0},
+ {"SETPARAM", 0x00, 2},
+ {"GETPARAM", 0x20, 1},
+ {"RUN", 0x50, 2},
+ {"STEPCLOCK", 0x58, 1},
+ {"MOVE", 0x40, 2},
+ {"GOTO", 0x60, 1},
+ {"GOTO_DIR", 0x68, 2},
+ {"GOUNTIL", 0x82, 3},
+ {"RELEASESW", 0x92, 2},
+ {"GOHOME", 0x70, 0},
+ {"GOMARK", 0x78, 0},
+ {"RESETPOS", 0xD8, 0},
+ {"RESETDEVICE", 0xC0, 0},
+ {"SOFTSTOP", 0xB0, 0},
+ {"HARDSTOP", 0xB8, 0},
+ {"SOFTHIZ", 0xA0, 0},
+ {"HARDHIZ", 0xA8, 0},
+ {"GETSTATUS", 0xD0, 0}
+};
+
+/**
+ * @brief The mnemonic names for the L6470 direction
+ */
+const sL6470_Direction_t L6470::_L6470_Direction[L6470DIRIDSIZE] = {
+ {"REV", 0x00}, //!< Reverse direction
+ {"FWD", 0x01} //!< Forward direction
+};
+
+/**
+ * @brief Action taken about ABS_POS register
+ */
+const sL6470_ACT_t L6470::_L6470_ACT[L6470ACTIDSIZE] = {
+ {"RST", 0x00}, //!< ABS_POS register is reset
+ {"CPY", 0x01} //!< ABS_POS register value is copied into the MARK register
+};
+
+/* End of L6470_Private_Constants */
+
+/**
+ * @defgroup L6470_Private_Variables
+ * @brief L6470 Private Variables.
+ * @{
+ */
+
+/* End of L6470_Private_Variables */
+
+
+/**
+ * @addtogroup L6470_Private_Functions
+ * @{
+ */
+
+
+/* Methods -------------------------------------------------------------------*/
+
+/**
+ * @brief Reset the structure used to store the identifier of the L6470
+ * application command and its the needed parameters.
+ * @param pL6470_AppCmdPkg The structure to be reset.
+ */
+void L6470::L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg)
+{
+ uint8_t id;
+
+ for(id=0; id<L6470DAISYCHAINSIZE; id++)
+ {
+ (pL6470_AppCmdPkg+id)->L6470_AppCmdId=(eL6470_AppCmdId_t)0;
+ (pL6470_AppCmdPkg+id)->p1=0;
+ (pL6470_AppCmdPkg+id)->p2=0;
+ (pL6470_AppCmdPkg+id)->p3=0;
+ }
+}
+
+/**
+ * @brief Fill the structure used to store the identifier of the L6470
+ * application command and its the needed parameters.
+ * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
+ * @param pL6470_AppCmdPkg The structure to be filled.
+ * @param L6470_AppCmdId The identifier of the L6470 application command to be sent.
+ * @param p1 The 1st parameter (if it is not needed it will be not considered).
+ * @param p2 The 2nd parameter (if it is not needed it will be not considered).
+ * @param p3 The 3rd parameter (if it is not needed it will be not considered).
+ */
+void L6470::L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3)
+{
+ (pL6470_AppCmdPkg+L6470_Id)->L6470_AppCmdId = L6470_AppCmdId;
+ (pL6470_AppCmdPkg+L6470_Id)->p1 = p1;
+ (pL6470_AppCmdPkg+L6470_Id)->p2 = p2;
+ (pL6470_AppCmdPkg+L6470_Id)->p3 = p3;
+}
+
+/**
+ * @brief This function will fill the column of the L6470_AppCmdPkg related
+ * the L6470 to be addressed inside the daisy chain.
+ *
+ * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
+ * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled.
+ * @param L6470_AppCmdId The identifier of the L6470 application command to be sent.
+ * @param p1 The 1st parameter (if it is not needed it will be not considered).
+ * @param p2 The 2nd parameter (if it is not needed it will be not considered).
+ * @param p3 The 3rd parameter (if it is not needed it will be not considered).
+ */
+void L6470::L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3)
+{
+ if(!L6470_DaisyChain_HalfPrepared)
+ {
+ L6470_DaisyChain_HalfPrepared = ONE_F; /* To avoid to delete the previous entered command */
+ L6470_ResetAppCmdPkg(pL6470_AppCmdPkg);
+ }
+
+ L6470_FillAppCmdPkg(pL6470_AppCmdPkg, L6470_AppCmdId, p1, p2, p3);
+}
+
+/**
+ * @brief This function will translate the data inside the L6470_AppCmdPkg into
+ * the right data to be sent via SPI to the L6470 daisy chain.
+ *
+ * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled.
+ * @param pL6470_DaisyChainSpiTxStruct Pointer to the structure used by SPI to send the commands.
+ */
+void L6470::L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct)
+{
+ uint8_t PkgId;
+ uint8_t PARAMLengthBytes; /* The number of bytes related to the numeric value for the addressed register */
+ uint8_t spibyte;
+
+ /* Reset the structure used to send the command to the L6470 Daisy Chain through the SPI */
+ uint8_t i = 0;
+ for(spibyte=0;spibyte<L6470MAXSPICMDBYTESIZE;spibyte++)
+ for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++)
+ *(pL6470_DaisyChainSpiTxStruct+(i++)) = 0x00;
+
+ for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++)
+ {
+ /* Build the 1st bytes to transmit with the binary code of the command */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) = (L6470_ApplicationCommand[(pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId].BinaryCode);
+
+ /* Perform the related L6470_AppCmdId */
+ switch((pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId)
+ {
+ case L6470_NOP_ID:
+ break;
+ case L6470_SETPARAM_ID:
+ /* Build the 1st bytes to transmit (PARAM) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address);
+
+ /* The length, in byte, of this register (PARAM) is... */
+ PARAMLengthBytes = L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].LengthByte;
+
+ /* Build the others bytes to transmit (VALUE) */
+ for (spibyte=1; spibyte<(PARAMLengthBytes+1); spibyte++)
+ {
+ *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(PARAMLengthBytes-spibyte)));
+ }
+ break;
+ case L6470_GETPARAM_ID:
+ /* Build the 1st bytes to transmit (PARAM) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address);
+ break;
+ case L6470_RUN_ID:
+ /* Build the 1st bytes to transmit (DIR) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
+
+ /* Build the others bytes to transmit (SPD) */
+ for (spibyte=1; spibyte<(3+1); spibyte++)
+ {
+ *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
+ }
+ break;
+ case L6470_STEPCLOCK_ID:
+ /* Build the 1st bytes to transmit (DIR) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
+ break;
+ case L6470_MOVE_ID:
+ /* Build the 1st bytes to transmit (DIR) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
+
+ /* Build the others bytes to transmit (N_STEP) */
+ for (spibyte=1; spibyte<(3+1); spibyte++)
+ {
+ *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
+ }
+ break;
+ case L6470_GOTO_ID:
+ /* Build the others bytes to transmit (ABS_POS) */
+ for (spibyte=1; spibyte<(3+1); spibyte++)
+ {
+ *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p1) >> (8*(3-spibyte)));
+ }
+ break;
+ case L6470_GOTODIR_ID:
+ /* Build the 1st bytes to transmit (DIR) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
+
+ /* Build the others bytes to transmit (ABS_POS) */
+ for (spibyte=1; spibyte<(3+1); spibyte++)
+ {
+ *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
+ }
+ break;
+ case L6470_GOUNTIL_ID:
+ /* Build the 1st bytes to transmit (ACT) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3);
+ /* Build the 1st bytes to transmit (DIR) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode);
+
+ /* Build the others bytes to transmit (SPD) */
+ for (spibyte=1; spibyte<(3+1); spibyte++)
+ {
+ *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p3) >> (8*(3-spibyte)));
+ }
+ break;
+ case L6470_RELEASESW_ID:
+ /* Build the 1st bytes to transmit (ACT) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3);
+ /* Build the 1st bytes to transmit (DIR) */
+ *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode);
+ break;
+ case L6470_GOHOME_ID:
+ break;
+ case L6470_GOMARK_ID:
+ break;
+ case L6470_RESETPOS_ID:
+ break;
+ case L6470_RESETDEVICE_ID:
+ break;
+ case L6470_SOFTSTOP_ID:
+ break;
+ case L6470_HARDSTOP_ID:
+ break;
+ case L6470_SOFTHIZ_ID:
+ break;
+ case L6470_HARDHIZ_ID:
+ break;
+ case L6470_GETSTATUS_ID:
+ break;
+ }
+ }
+}
+
+/* End of L6470_Private_Functions */
+
+/**
+ * @addtogroup L6470_Exported_Functions
+ * @{
+ */
+
+/**
+ * @addtogroup L6470_Conversion_Functions
+ * @brief The following functions act just on one driver inside the L6470
+ * daisy chain. The command is immediately sent.
+ * @{
+ */
+
+ /**
+ * @brief Convert the absolute position as 2's complement format into the signed number.
+ *
+ * @param AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1].
+ * @retval Position The position as signed number.
+ */
+int32_t L6470::L6470_AbsPos_2_Position(uint32_t AbsPos)
+{
+ if (AbsPos > L6470_MAX_POSITION)
+ return (AbsPos - (L6470_POSITION_RANGE + 1));
+ else
+ return AbsPos;
+}
+
+/**
+ * @brief Convert the position as signed number into absolute position as 2's complement format.
+ *
+ * @param Position The position as signed number.
+ * @retval AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1].
+ */
+uint32_t L6470::L6470_Position_2_AbsPos(int32_t Position)
+{
+ if ((Position >= 0) && (Position <= L6470_MAX_POSITION))
+ return Position;
+ else
+ {
+ if ((Position >= L6470_MIN_POSITION) && (Position < 0))
+ return (Position + (L6470_POSITION_RANGE + 1));
+ else
+ return (L6470_POSITION_RANGE + 1); // OVF
+ }
+}
+
+/**
+ * @brief Convert the SPEED register value into step/s.
+ *
+ * @param Speed The SPEED register value.
+ * @retval step/s The speed as step/s.
+ */
+float L6470::L6470_Speed_2_Step_s(uint32_t Speed)
+{
+ return (Speed * ((float)14.9012e-3));
+}
+
+/**
+ * @brief Convert the speed as step/s into a right value for SPEED register.
+ *
+ * @param step/s The speed as step/s.
+ * @retval Speed The SPEED register value.
+ */
+uint32_t L6470::L6470_Step_s_2_Speed(float Step_s)
+{
+ if (Step_s <= (L6470_MAX_SPEED * ((float)14.9012e-3)))
+ return (uint32_t)(Step_s / ((float)14.9012e-3));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the ACC register value into step/(s^2).
+ *
+ * @param Acc The ACC register value.
+ * @retval step/(s^2) The acceleration as step/(s^2).
+ */
+float L6470::L6470_Acc_2_Step_s2(uint16_t Acc)
+{
+ if (Acc <= L6470_MAX_ACC)
+ return (Acc * ((float)1.4552e1));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the acceleartion as step/(s^2) into a right value for ACC register.
+ *
+ * @param step/(s^2) The acceleration as step/(s^2).
+ * @retval Acc The ACC register value.
+ */
+uint16_t L6470::L6470_Step_s2_2_Acc(float Step_s2)
+{
+ if (Step_s2 <= (L6470_MAX_ACC * ((float)1.4552e1)))
+ return (uint16_t)(Step_s2 / ((float)1.4552e1));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the DEC register value into step/(s^2).
+ *
+ * @param Dec The DEC register value.
+ * @retval step/(s^2) The deceleration as step/(s^2).
+ */
+float L6470::L6470_Dec_2_Step_s2(uint16_t Dec)
+{
+ if (Dec <= L6470_MAX_DEC)
+ return (Dec * ((float)1.4552e1));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the deceleration as step/(s^2) into a right value for DEC register.
+ *
+ * @param step/(s^2) The deceleration as step/(s^2).
+ * @retval Dec The DEC register value.
+ */
+uint16_t L6470::L6470_Step_s2_2_Dec(float Step_s2)
+{
+ if (Step_s2 <= (L6470_MAX_DEC * ((float)1.4552e1)))
+ return (uint16_t)(Step_s2 / ((float)1.4552e1));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the MAX_SPEED register value into step/s.
+ *
+ * @param MaxSpeed The MAX_SPEED register value.
+ * @retval step/s The max speed as step/s.
+ */
+float L6470::L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed)
+{
+ if (MaxSpeed <= L6470_MAX_MAX_SPEED)
+ return (MaxSpeed * ((float)15.2588));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the max speed as step/s into a right value for MAX_SPEED register.
+ *
+ * @param step/s The max speed as step/s.
+ * @retval MaxSpeed The MAX_SPEED register value.
+ */
+uint16_t L6470::L6470_Step_s_2_MaxSpeed(float Step_s)
+{
+ if (Step_s <= (L6470_MAX_MAX_SPEED * ((float)15.2588)))
+ return (uint16_t)(Step_s / ((float)15.2588));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the MIN_SPEED register value into step/s.
+ *
+ * @param MinSpeed The MIN_SPEED register value.
+ * @retval step/s The min speed as step/s.
+ */
+float L6470::L6470_MinSpeed_2_Step_s(uint16_t MinSpeed)
+{
+ if (MinSpeed <= L6470_MAX_MIN_SPEED)
+ return (MinSpeed * ((float)238.4186e-3));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the min speed as step/s into a right value for MIN_SPEED register.
+ *
+ * @param step/s The min speed as step/s.
+ * @retval MinSpeed The MIN_SPEED register value.
+ */
+uint16_t L6470::L6470_Step_s_2_MinSpeed(float Step_s)
+{
+ if (Step_s <= (L6470_MAX_MIN_SPEED * ((float)238.4186e-3)))
+ return (uint16_t)(Step_s / ((float)238.4186e-3));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the FS_SPD register value into step/s.
+ *
+ * @param FsSpd The FS_SPD register value.
+ * @retval step/s The full-step speed as step/s.
+ */
+float L6470::L6470_FsSpd_2_Step_s(uint16_t FsSpd)
+{
+ if (FsSpd <= L6470_MAX_FS_SPD)
+ return ((FsSpd+0.5) * ((float)15.25));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the full-step speed as step/s into a right value for FS_SPD register.
+ *
+ * @param step/s The full-step speed as step/s.
+ * @retval FsSpd The FS_SPD register value.
+ */
+uint16_t L6470::L6470_Step_s_2_FsSpd(float Step_s)
+{
+ if (Step_s <= ((L6470_MAX_FS_SPD+0.5) * ((float)15.25)))
+ return (uint16_t)((float)(Step_s / ((float)15.25)) - (float)0.5);
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the INT_SPEED register value into step/s.
+ *
+ * @param IntSpeed The INT_SPEED register value.
+ * @retval step/s The intersect speed as step/s.
+ */
+float L6470::L6470_IntSpeed_2_Step_s(uint16_t IntSpeed)
+{
+ if (IntSpeed <= L6470_MAX_INT_SPEED)
+ return (IntSpeed * ((float)59.6046e-3));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
+ *
+ * @param step/s The full-step speed as step/s.
+ * @retval FsSpd The FS_SPD register value.
+ */
+uint16_t L6470::L6470_Step_s_2_IntSpeed(float Step_s)
+{
+ if (Step_s <= (L6470_MAX_INT_SPEED * ((float)59.6046e-3)))
+ return (uint16_t)(Step_s / ((float)59.6046e-3));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the ST_SLP register value into s/step.
+ *
+ * @param StartSlope The ST_SLP register value.
+ * @retval s/step The start slope as s/step.
+ */
+float L6470::L6470_StSlp_2_s_Step(uint8_t StSlp)
+{
+// if (StSlp <= L6470_MAX_ST_SLP)
+ return (StSlp * ((float)1.5686e-5));
+// else
+// return 0; // Warning
+}
+
+/**
+ * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
+ *
+ * @param step/s The full-step speed as step/s.
+ * @retval FsSpd The FS_SPD register value.
+ */
+uint8_t L6470::L6470_s_Step_2_StSlp(float s_Step)
+{
+ if (s_Step <= (L6470_MAX_ST_SLP * ((float)1.5686e-5)))
+ return (uint8_t)(s_Step / ((float)1.5686e-5));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the INT_SPEED register value into step/s.
+ *
+ * @param IntSpeed The INT_SPEED register value.
+ * @retval step/s The intersect speed as step/s.
+ */
+float L6470::L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc)
+{
+// if (FnSlpAcc <= L6470_MAX_FN_SLP_ACC)
+ return (FnSlpAcc * ((float)1.5686e-5));
+// else
+// return 0; // Warning
+}
+
+/**
+ * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
+ *
+ * @param step/s The full-step speed as step/s.
+ * @retval FsSpd The FS_SPD register value.
+ */
+uint8_t L6470::L6470_s_Step_2_FnSlpAcc(float s_Step)
+{
+ if (s_Step <= (L6470_MAX_FN_SLP_ACC * ((float)1.5686e-5)))
+ return (uint8_t)(s_Step / ((float)1.5686e-5));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the INT_SPEED register value into step/s.
+ *
+ * @param IntSpeed The INT_SPEED register value.
+ * @retval step/s The intersect speed as step/s.
+ */
+float L6470::L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec)
+{
+// if (FnSlpDec <= L6470_MAX_FN_SLP_DEC)
+ return (FnSlpDec * ((float)1.5686e-5));
+// else
+// return 0; // Warning
+}
+
+/**
+ * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
+ *
+ * @param step/s The full-step speed as step/s.
+ * @retval FsSpd The FS_SPD register value.
+ */
+uint8_t L6470::L6470_s_Step_2_FnSlpDec(float s_Step)
+{
+ if (s_Step <= (L6470_MAX_FN_SLP_DEC * ((float)1.5686e-5)))
+ return (uint8_t)(s_Step / ((float)1.5686e-5));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the OCD_TH register value into mA.
+ *
+ * @param OcdTh The OCD_TH register value.
+ * @retval mA The overcurrent threshold as mA.
+ */
+float L6470::L6470_OcdTh_2_mA(uint8_t OcdTh)
+{
+ if (OcdTh <= L6470_MAX_OCD_TH)
+ return ((OcdTh+1) * ((float)375));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the overcurrent threshold as mA into a right value for OCD_TH register.
+ *
+ * @param mA The overcurrent threshold as mA.
+ * @retval OcdTh The OCD_TH register value.
+ */
+uint8_t L6470::L6470_mA_2_OcdTh(float mA)
+{
+ float result, decimal;
+
+ if (mA <= ((L6470_MAX_OCD_TH+1) * ((float)375)))
+ {
+ result = (mA / ((float)375));
+ decimal = result - (uint8_t)result;
+
+ if (decimal < (float)0.5)
+ return ((uint8_t)result - 1);
+ else
+ return ((uint8_t)result);
+ }
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the STALL_TH register value into mA.
+ *
+ * @param StallTh The STALL_TH register value.
+ * @retval mA The stall detection threshold as mA.
+ */
+float L6470::L6470_StallTh_2_mA(uint8_t StallTh)
+{
+ if (StallTh <= L6470_MAX_STALL_TH)
+ return ((StallTh+1) * ((float)31.25));
+ else
+ return 0; // Warning
+}
+
+/**
+ * @brief Convert the stall detection threshold as mA into a right value for STALL_TH register.
+ *
+ * @param mA The stall detection threshold as mA.
+ * @retval StallTh The STALL_TH register value.
+ */
+uint8_t L6470::L6470_mA_2_StallTh(float mA)
+{
+ float result, decimal;
+
+ if (mA <= ((L6470_MAX_STALL_TH+1) * ((float)31.25)))
+ {
+ result = (mA / ((float)31.25));
+ decimal = result - (uint8_t)result;
+
+ if (decimal < (float)0.5)
+ return ((uint8_t)result - 1);
+ else
+ return ((uint8_t)result);
+ }
+ else
+ return 0; // Warning
+}
+
+/* End of L6470_Conversion_Functions */
+
+/**
+ * @addtogroup L6470_AppCMDs
+ * @{
+ */
+
+/**
+ * @brief SetParam command sets the register value equal to a new value.
+ *
+ * @param L6470_RegId The identifier of the L6470 register to be addressed.
+ * @param Value The new value.
+ */
+void L6470::L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief GetParam command reads the register value.
+ *
+ * @param L6470_RegId The identifier of the L6470 register to be addressed.
+ *
+ * @retval ReceivedValue The register value.
+ */
+uint32_t L6470::L6470_GetParam(eL6470_RegId_t L6470_RegId)
+{
+ uint8_t ValueLengthByte;
+ uint32_t ReceivedValue;
+
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+
+ ValueLengthByte = L6470_Register[L6470_RegId].LengthByte;
+
+ ReceivedValue = L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, ValueLengthByte);
+
+ return ReceivedValue;
+}
+
+/**
+ * @brief Run command produces a motion at fixed speed.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
+ */
+void L6470::L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief StepClock command switches the device in Step-clock mode.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ */
+void L6470::L6470_StepClock(eL6470_DirId_t L6470_DirId)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief Move command produces a motion of N_STEP microsteps.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param N_Step The number of microsteps.
+ */
+void L6470::L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief GoTo command produces a motion to ABS_POS absolute position through the shortest path.
+ *
+ * @param AbsPos The target absolute position.
+ */
+void L6470::L6470_GoTo(uint32_t AbsPos)
+{
+ if (AbsPos <= L6470_POSITION_RANGE)
+ {
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+ }
+}
+
+/**
+ * @brief GoTo_DIR command produces a motion to ABS_POS absolute position imposing a direction.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param AbsPos The target absolute position.
+ */
+void L6470::L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos)
+{
+ if (AbsPos <= L6470_POSITION_RANGE)
+ {
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+ }
+}
+
+/**
+ * @brief GoUntil command produces a motion at fixed speed imposing a direction
+ * until an external switch turn-on event occurs.
+ *
+ * @param L6470_ActId The identifier of the L6470 action about the absolute position.
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
+ */
+void L6470::L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief ReleaseSW command produces a motion at minimum speed imposing a direction
+ * until SW is released.
+ *
+ * @param L6470_ActId The identifier of the L6470 action about the absolute position.
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ */
+void L6470::L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief GoHome command produces a motion to the HOME position (zero position)
+ * via the shortest path.
+ *
+ */
+void L6470::L6470_GoHome(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief GoMark command produces a motion to the MARK position performing the
+ * minimum path.
+ *
+ */
+void L6470::L6470_GoMark(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief ResetPos command resets the ABS_POS register to zero.
+ *
+ */
+void L6470::L6470_ResetPos(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief ResetDevice command resets the device to power-up conditions.
+ *
+ */
+void L6470::L6470_ResetDevice(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief SoftStop command causes an immediate deceleration to zero speed and
+ * a consequent motor stop; the deceleration value used is the one stored
+ * in the DEC register.
+ *
+ */
+void L6470::L6470_SoftStop(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief HardStop command causes an immediate motor stop with infinite deceleration.
+ *
+ */
+void L6470::L6470_HardStop(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief SoftHiZ command disables the power bridges (high impedance state)
+ * after a deceleration to zero; the deceleration value used is the one
+ * stored in the DEC register.
+ *
+ */
+void L6470::L6470_SoftHiZ(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief HardHiZ command immediately disables the power bridges (high impedance state).
+ *
+ */
+void L6470::L6470_HardHiZ(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief GetStatus command returns the STATUS register value.
+ *
+ *
+ * @retval ReceivedValue The register value.
+ */
+uint16_t L6470::L6470_GetStatus(void)
+{
+ uint16_t ReceivedValue;
+
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0);
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+
+ ReceivedValue = (uint16_t)L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, 2);
+
+ return ReceivedValue;
+}
+
+/* End of L6470_AppCMDs */
+
+/**
+ * @addtogroup L6470_AppCMDs_ToBePrepared
+ * @{
+ */
+
+/**
+ * @brief Prepare to send @ref L6470_SetParam command.
+ *
+ * @param L6470_RegId The identifier of the L6470 register to be addressed.
+ * @param Value The new value.
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_GetParam command.
+ *
+ * @param L6470_Id The L6470 identifier inside the daisy chain.
+ * @param L6470_RegId The identifier of the L6470 register to be addressed.
+ *
+ * @retval ReceivedValue The register value.
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_Run command.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_StepClock command.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_Move command.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param N_Step The number of microsteps.
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_GoTo command.
+ *
+ * @param AbsPos The target absolute position.
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareGoTo(uint32_t AbsPos)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_GoToDIR command.
+ *
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param AbsPos The target absolute position.
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_GoUntil command.
+ *
+ * @param L6470_ActId The identifier of the L6470 action about the absolute position.
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_ReleaseSW.
+ *
+ * @param L6470_ActId The identifier of the L6470 action about the absolute position.
+ * @param L6470_DirId The identifier of the L6470 motion direction.
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_GoHome command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareGoHome(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_GoMark command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareGoMark(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_ResetPos command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareResetPos(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_ResetDevice command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareResetDevice(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_SoftStop command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareSoftStop(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_HardStop command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareHardStop(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_SoftHiZ command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareSoftHiZ(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_HardHiZ command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareHardHiZ(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0);
+}
+
+/**
+ * @brief Prepare to send @ref L6470_GetStatus command.
+ *
+ *
+ * @note This function will properly fill the right column of the L6470_AppCmdPkg.
+ * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
+ */
+void L6470::L6470_PrepareGetStatus(void)
+{
+ L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0);
+}
+
+/* End of L6470_AppCMDs_ToBePrepared */
+
+/**
+ * @brief Send via SPI the command stored inside the L6470_AppCmdPkg to the
+ * L6470 daisy chain.
+ *
+ * @retval (uint8_t*)data->L6470_DaisyChainSpiRxStruct The pointer to the structure
+ * containing returned values from each L6470 of the daisy chain for each
+ * sent SPI data.
+ */
+uint8_t* L6470::L6470_PerformPreparedApplicationCommand(void)
+{
+ L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
+ L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
+
+ return (uint8_t*)(L6470_DaisyChainSpiRxStruct);
+}
+
+/**
+ * @brief Send command to the L6470 daisy chain via SPI
+ * @param pL6470_DaisyChainSpiTxStruct Pointer to the matrix array of bytes to be sent to the daisy chain L6470
+ * @param pL6470_DaisyChainSpiRxStruct Pointer to the matrix array of bytes to be received from the daisy chain L6470
+ */
+void L6470::L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct)
+{
+ uint8_t spibyte;
+
+ L6470_DaisyChain_HalfPrepared = ZERO_F;
+
+ /* Send all command bytes via SPI */
+ for(spibyte=0; spibyte < L6470MAXSPICMDBYTESIZE; spibyte++)
+ {
+ /* Send the command via SPI */
+ L6470_SPI_Communication((pL6470_DaisyChainSpiTxStruct+(spibyte * L6470DAISYCHAINSIZE)), (pL6470_DaisyChainSpiRxStruct+(spibyte * L6470DAISYCHAINSIZE)), L6470DAISYCHAINSIZE, 10);
+
+ //_DELAY(TDISCS);
+ uint8_t delay_cnt;
+ for (delay_cnt=0; delay_cnt<20; delay_cnt++) __NOP(); //!<Simply deselect time delay for SPI nCS
+ }
+}
+
+/**
+ * @brief Extracts the data returned by the L6470 from the matrix that
+ * contains the received SPI data.
+ * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
+ * @param pL6470_DaisyChainSpiRxStruct uint8_t-pointer to the matrix that
+ * contains the received data by SPI from the L6470 daisy chain.
+ * @param LengthByte The number of bytes about the received value.
+ */
+uint32_t L6470::L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte)
+{
+ uint32_t value;
+ uint8_t i;
+
+ value = 0x000000;
+ for (i=1; i<=(L6470MAXSPICMDBYTESIZE-1); i++)
+ {
+ value |= (*(pL6470_DaisyChainSpiRxStruct+(i*L6470DAISYCHAINSIZE)+L6470_Id))<<((LengthByte-i)*8);
+ }
+
+ return value;
+}
+
+/**
+ * @brief Check the state of a flag inside the L6470 STATUS register.
+ *
+ * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
+ * @param L6470_StatusRegisterFlagId The identifier of the L6470 STATUS flag to be checked.
+ *
+ * @retval state The flag state.
+ */
+
+uint8_t L6470::L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId)
+{
+ uint8_t state = 0;
+
+ *((uint16_t*)pL6470_StatusRegister) = L6470_GetParam(L6470_STATUS_ID);
+
+ switch(L6470_StatusRegisterFlagId)
+ {
+ case HiZ_ID:
+ state = pL6470_StatusRegister->HiZ;
+ break;
+ case BUSY_ID:
+ state = pL6470_StatusRegister->BUSY;
+ break;
+ case SW_F_ID:
+ state = pL6470_StatusRegister->SW_F;
+ break;
+ case SW_EVN_ID:
+ state = pL6470_StatusRegister->SW_EVN;
+ break;
+ case DIR_ID:
+ state = pL6470_StatusRegister->DIR;
+ break;
+ case MOT_STATUS_ID:
+ state = pL6470_StatusRegister->MOT_STATUS;
+ break;
+ case NOTPERF_CMD_ID:
+ state = pL6470_StatusRegister->NOTPERF_CMD;
+ break;
+ case WRONG_CMD_ID:
+ state = pL6470_StatusRegister->WRONG_CMD;
+ break;
+ case UVLO_ID:
+ state = pL6470_StatusRegister->UVLO;
+ break;
+ case TH_WRN_ID:
+ state = pL6470_StatusRegister->TH_WRN;
+ break;
+ case TH_SD_ID:
+ state = pL6470_StatusRegister->TH_SD;
+ break;
+ case OCD_ID:
+ state = pL6470_StatusRegister->OCD;
+ break;
+ case STEP_LOSS_A_ID:
+ state = pL6470_StatusRegister->STEP_LOSS_A;
+ break;
+ case STEP_LOSS_B_ID:
+ state = pL6470_StatusRegister->STEP_LOSS_B;
+ break;
+ case SCK_MOD_ID:
+ state = pL6470_StatusRegister->SCK_MOD;
+ break;
+ }
+
+ return state;
+}
+
+/**
+ * @brief Return the mnemonic name for the L6470 register.
+ * @param id The identifier of the L6470 register.
+ */
+uint8_t *L6470::L6470_GetRegisterName(uint8_t id)
+{
+ if (id < L6470REGIDSIZE)
+ {
+ return (uint8_t*)L6470_Register[id].Name;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/**
+ * @brief Configures the L6470 registers.
+ * @param init The pointer to the initialization structure.
+ */
+status_t L6470::L6470_Config(void *init)
+{
+ /* Disable the L6470. */
+ L6470_DISABLE();
+
+ /* Enable the L6470. */
+ L6470_ENABLE();
+
+ /* Reset devices. */
+ reset_device();
+
+ /* Reset Status Register flags. */
+ get_status();
+
+ /* Prepare the 'Register' field of StepperMotorDriverHandle */
+ L6470_init_t *MotorParameterData = (L6470_init_t *) init;
+ StepperMotorRegister.ACC = L6470_Step_s2_2_Acc(MotorParameterData->acc);
+ StepperMotorRegister.DEC = L6470_Step_s2_2_Dec(MotorParameterData->dec);
+ StepperMotorRegister.MAX_SPEED = L6470_Step_s_2_MaxSpeed(MotorParameterData->maxspeed);
+ StepperMotorRegister.MIN_SPEED = L6470_Step_s_2_MinSpeed(MotorParameterData->minspeed);
+ StepperMotorRegister.FS_SPD = L6470_Step_s_2_FsSpd(MotorParameterData->fsspd);
+ StepperMotorRegister.KVAL_HOLD = (uint8_t)((float)((float)(MotorParameterData->kvalhold * 256) / (MotorParameterData->motorvoltage)));
+ StepperMotorRegister.KVAL_RUN = (uint8_t)((float)((float)(MotorParameterData->kvalrun * 256) / (MotorParameterData->motorvoltage)));
+ StepperMotorRegister.KVAL_ACC = (uint8_t)((float)((float)(MotorParameterData->kvalacc * 256) / (MotorParameterData->motorvoltage)));
+ StepperMotorRegister.KVAL_DEC = (uint8_t)((float)((float)(MotorParameterData->kvaldec * 256) / (MotorParameterData->motorvoltage)));
+ StepperMotorRegister.INT_SPEED = L6470_Step_s_2_IntSpeed(MotorParameterData->intspeed);
+ StepperMotorRegister.ST_SLP = L6470_s_Step_2_StSlp(MotorParameterData->stslp);
+ StepperMotorRegister.FN_SLP_ACC = L6470_s_Step_2_FnSlpAcc(MotorParameterData->fnslpacc);
+ StepperMotorRegister.FN_SLP_DEC = L6470_s_Step_2_FnSlpDec(MotorParameterData->fnslpdec);
+ StepperMotorRegister.K_THERM = MotorParameterData->kterm;
+ StepperMotorRegister.OCD_TH = L6470_mA_2_OcdTh(MotorParameterData->ocdth);
+ StepperMotorRegister.STALL_TH = L6470_mA_2_StallTh(MotorParameterData->stallth);
+ StepperMotorRegister.ALARM_EN = MotorParameterData->alarmen;
+ StepperMotorRegister.CONFIG = MotorParameterData->config;
+ StepperMotorRegister.STEP_MODE = MotorParameterData->step_sel;
+
+ /* Write the L6470 registers with the prepared data */
+ L6470_SetParam(L6470_ACC_ID, StepperMotorRegister.ACC);
+ L6470_SetParam(L6470_DEC_ID, StepperMotorRegister.DEC);
+ L6470_SetParam(L6470_MAX_SPEED_ID, StepperMotorRegister.MAX_SPEED);
+ L6470_SetParam(L6470_MIN_SPEED_ID, StepperMotorRegister.MIN_SPEED);
+ L6470_SetParam(L6470_FS_SPD_ID, StepperMotorRegister.FS_SPD);
+ L6470_SetParam(L6470_KVAL_HOLD_ID, StepperMotorRegister.KVAL_HOLD);
+ L6470_SetParam(L6470_KVAL_RUN_ID, StepperMotorRegister.KVAL_RUN);
+ L6470_SetParam(L6470_KVAL_ACC_ID, StepperMotorRegister.KVAL_ACC);
+ L6470_SetParam(L6470_KVAL_DEC_ID, StepperMotorRegister.KVAL_DEC);
+ L6470_SetParam(L6470_INT_SPEED_ID, StepperMotorRegister.INT_SPEED);
+ L6470_SetParam(L6470_ST_SLP_ID, StepperMotorRegister.ST_SLP);
+ L6470_SetParam(L6470_FN_SLP_ACC_ID, StepperMotorRegister.FN_SLP_ACC);
+ L6470_SetParam(L6470_FN_SLP_DEC_ID, StepperMotorRegister.FN_SLP_DEC);
+ L6470_SetParam(L6470_K_THERM_ID, StepperMotorRegister.K_THERM);
+ L6470_SetParam(L6470_OCD_TH_ID, StepperMotorRegister.OCD_TH);
+ L6470_SetParam(L6470_STALL_TH_ID, StepperMotorRegister.STALL_TH);
+ L6470_SetParam(L6470_ALARM_EN_ID, StepperMotorRegister.ALARM_EN);
+ L6470_SetParam(L6470_CONFIG_ID, StepperMotorRegister.CONFIG);
+ if (!set_step_mode((StepperMotor::step_mode_t) StepperMotorRegister.STEP_MODE))
+ return COMPONENT_ERROR;
+
+ return COMPONENT_OK;
+}
+
+/* End of L6470_Exported_Functions */
+
+/* End of L6470 */
+
+/* End of Components */
+
+/* End of BSP */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/L6470/L6470.h Fri Mar 10 15:23:54 2017 +0000
@@ -0,0 +1,1584 @@
+/**
+ ******************************************************************************
+ * @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
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+
+/* 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_CLASS_H
+#define __L6470_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/* 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"
+
+
+/* Classes -------------------------------------------------------------------*/
+
+/**
+ * @brief Class representing a L6470 component.
+ */
+class L6470 : public StepperMotor
+{
+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 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) {}
+
+
+ /*** 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);
+ }
+
+ /**
+ * @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();
+ }
+
+ /**
+ * @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_SoftHiZ();
+ }
+
+ /**
+ * @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;
+ }
+
+ /**
+ * @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;
+ }
+
+ /**
+ * @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;
+ }
+
+ /**
+ * @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);
+
+ 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 ***/
+
+ /* 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_SoftHiZ(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_PrepareSoftHiZ(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****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/L6470/L6470_def.h Fri Mar 10 15:23:54 2017 +0000
@@ -0,0 +1,315 @@
+/**
+ ******************************************************************************
+ * @file L6470_def.h
+ * @date 01/10/2014 12:00:00
+ * @brief This file contains definitions, exported variables and function
+ * prototypes related to the L6470.
+ ******************************************************************************
+ *
+ * COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __L6470_H
+#define __L6470_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "../Common/microstepping_motor_def.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;
+
+/**
+ * @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.
+ */
+/* 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
+{
+ 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;
+
+/**
+ * @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;
+
+
+/* Functions -----------------------------------------------------------------*/
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @addtogroup L6470
+ * @{
+ */
+
+/** @defgroup L6470_Imported_Functions L6470_Imported_Functions
+ * @{
+ */
+
+/* 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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __L6470_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Components/l6470/L6470.cpp Fri Mar 10 11:09:21 2017 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1460 +0,0 @@
-/**
- ******************************************************************************
- * @file l6470_class.cpp
- * @date 01/10/2014 12:00:00
- * @brief This file provides set of firmware functions to manage the
- * L6470.
- ******************************************************************************
- *
- * COPYRIGHT(c) 2014 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-
-/* 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.c
- Revision: 0
-*/
-
-
-/* Includes ------------------------------------------------------------------*/
-
-#include "l6470.h"
-
-
-/* Variables -----------------------------------------------------------------*/
-
-/* Number of instantiated devices on an expansion board. */
-uint8_t L6470::number_of_devices = 0;
-
-/* SPI Transmission for Daisy-Chain Configuration. */
-eFlagStatus_t L6470::L6470_DaisyChain_HalfPrepared;
-sL6470_AppCmdPkg_t L6470::L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
-uint8_t L6470::L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
-uint8_t L6470::L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
-
-/**
- * @brief 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)
- */
-const sL6470_Register_t L6470::_L6470_Register[L6470REGIDSIZE] = {
- {0x01 , "ABS_POS", 22, 3, 0x000000}, //!< Current position
- {0x02 , "EL_POS", 9, 2, 0x000}, //!< Electrical position
- {0x03 , "MARK", 22, 3, 0x000000}, //!< Mark position
- {0x04 , "SPEED", 20, 3, 0x0000}, //!< Current speed
- {0x05 , "ACC", 12, 2, 0x08A}, //!< Acceleration
- {0x06 , "DEC", 12, 2, 0x08A}, //!< Deceleration
- {0x07 , "MAX_SPEED", 10, 2, 0x041}, //!< Maximum speed
- {0x08 , "MIN_SPEED", 13, 2, 0x000}, //!< Minimum speed
- {0x15 , "FS_SPD", 10, 2, 0x027}, //!< Full-step speed
- {0x09 , "KVAL_HOLD", 8, 1, 0x29}, //!< Holding KVAL
- {0x0A , "KVAL_RUN", 8, 1, 0x29}, //!< Constant speed KVAL
- {0x0B , "KVAL_ACC", 8, 1, 0x29}, //!< Acceleration starting KVAL
- {0x0C , "KVAL_DEC", 8, 1, 0x29}, //!< Deceleration starting KVAL
- {0x0D , "INT_SPEED", 14, 2, 0x0408}, //!< Intersect speed
- {0x0E , "ST_SLP", 8, 1, 0x19}, //!< Start slope
- {0x0F , "FN_SLP_ACC", 8, 1, 0x29}, //!< Acceleration final slope
- {0x10 , "FN_SLP_DEC", 8, 1, 0x29}, //!< Deceleration final slope
- {0x11 , "K_THERM", 4, 1, 0x0}, //!< Thermal compensation factor
- {0x12 , "ADC_OUT", 5, 1, 0x00}, //!< ADC output, (the reset value is according to startup conditions)
- {0x13 , "OCD_TH", 4, 1, 0x8}, //!< OCD threshold
- {0x14 , "STALL_TH", 7, 1, 0x40}, //!< STALL threshold
- {0x16 , "STEP_MODE", 8, 1, 0x7}, //!< Step mode
- {0x17 , "ALARM_EN", 8, 1, 0xFF}, //!< Alarm enable
- {0x18 , "CONFIG", 16, 2, 0x2E88}, //!< IC configuration
- {0x19 , "STATUS", 16, 2, 0x0000} //!< Status, (the reset value is according to startup conditions)
-};
-
-/**
- * @brief 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)
- */
-const sL6470_ApplicationCommand_t L6470::_L6470_ApplicationCommand[L6470APPCMDIDSIZE] = {
- {"NOP", 0x00, 0},
- {"SETPARAM", 0x00, 2},
- {"GETPARAM", 0x20, 1},
- {"RUN", 0x50, 2},
- {"STEPCLOCK", 0x58, 1},
- {"MOVE", 0x40, 2},
- {"GOTO", 0x60, 1},
- {"GOTO_DIR", 0x68, 2},
- {"GOUNTIL", 0x82, 3},
- {"RELEASESW", 0x92, 2},
- {"GOHOME", 0x70, 0},
- {"GOMARK", 0x78, 0},
- {"RESETPOS", 0xD8, 0},
- {"RESETDEVICE", 0xC0, 0},
- {"SOFTSTOP", 0xB0, 0},
- {"HARDSTOP", 0xB8, 0},
- {"SOFTHIZ", 0xA0, 0},
- {"HARDHIZ", 0xA8, 0},
- {"GETSTATUS", 0xD0, 0}
-};
-
-/**
- * @brief The mnemonic names for the L6470 direction
- */
-const sL6470_Direction_t L6470::_L6470_Direction[L6470DIRIDSIZE] = {
- {"REV", 0x00}, //!< Reverse direction
- {"FWD", 0x01} //!< Forward direction
-};
-
-/**
- * @brief Action taken about ABS_POS register
- */
-const sL6470_ACT_t L6470::_L6470_ACT[L6470ACTIDSIZE] = {
- {"RST", 0x00}, //!< ABS_POS register is reset
- {"CPY", 0x01} //!< ABS_POS register value is copied into the MARK register
-};
-
-/* End of L6470_Private_Constants */
-
-/**
- * @defgroup L6470_Private_Variables
- * @brief L6470 Private Variables.
- * @{
- */
-
-/* End of L6470_Private_Variables */
-
-
-/**
- * @addtogroup L6470_Private_Functions
- * @{
- */
-
-
-/* Methods -------------------------------------------------------------------*/
-
-/**
- * @brief Reset the structure used to store the identifier of the L6470
- * application command and its the needed parameters.
- * @param pL6470_AppCmdPkg The structure to be reset.
- */
-void L6470::L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg)
-{
- uint8_t id;
-
- for(id=0; id<L6470DAISYCHAINSIZE; id++)
- {
- (pL6470_AppCmdPkg+id)->L6470_AppCmdId=(eL6470_AppCmdId_t)0;
- (pL6470_AppCmdPkg+id)->p1=0;
- (pL6470_AppCmdPkg+id)->p2=0;
- (pL6470_AppCmdPkg+id)->p3=0;
- }
-}
-
-/**
- * @brief Fill the structure used to store the identifier of the L6470
- * application command and its the needed parameters.
- * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
- * @param pL6470_AppCmdPkg The structure to be filled.
- * @param L6470_AppCmdId The identifier of the L6470 application command to be sent.
- * @param p1 The 1st parameter (if it is not needed it will be not considered).
- * @param p2 The 2nd parameter (if it is not needed it will be not considered).
- * @param p3 The 3rd parameter (if it is not needed it will be not considered).
- */
-void L6470::L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3)
-{
- (pL6470_AppCmdPkg+L6470_Id)->L6470_AppCmdId = L6470_AppCmdId;
- (pL6470_AppCmdPkg+L6470_Id)->p1 = p1;
- (pL6470_AppCmdPkg+L6470_Id)->p2 = p2;
- (pL6470_AppCmdPkg+L6470_Id)->p3 = p3;
-}
-
-/**
- * @brief This function will fill the column of the L6470_AppCmdPkg related
- * the L6470 to be addressed inside the daisy chain.
- *
- * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
- * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled.
- * @param L6470_AppCmdId The identifier of the L6470 application command to be sent.
- * @param p1 The 1st parameter (if it is not needed it will be not considered).
- * @param p2 The 2nd parameter (if it is not needed it will be not considered).
- * @param p3 The 3rd parameter (if it is not needed it will be not considered).
- */
-void L6470::L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3)
-{
- if(!L6470_DaisyChain_HalfPrepared)
- {
- L6470_DaisyChain_HalfPrepared = ONE_F; /* To avoid to delete the previous entered command */
- L6470_ResetAppCmdPkg(pL6470_AppCmdPkg);
- }
-
- L6470_FillAppCmdPkg(pL6470_AppCmdPkg, L6470_AppCmdId, p1, p2, p3);
-}
-
-/**
- * @brief This function will translate the data inside the L6470_AppCmdPkg into
- * the right data to be sent via SPI to the L6470 daisy chain.
- *
- * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled.
- * @param pL6470_DaisyChainSpiTxStruct Pointer to the structure used by SPI to send the commands.
- */
-void L6470::L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct)
-{
- uint8_t PkgId;
- uint8_t PARAMLengthBytes; /* The number of bytes related to the numeric value for the addressed register */
- uint8_t spibyte;
-
- /* Reset the structure used to send the command to the L6470 Daisy Chain through the SPI */
- uint8_t i = 0;
- for(spibyte=0;spibyte<L6470MAXSPICMDBYTESIZE;spibyte++)
- for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++)
- *(pL6470_DaisyChainSpiTxStruct+(i++)) = 0x00;
-
- for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++)
- {
- /* Build the 1st bytes to transmit with the binary code of the command */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) = (L6470_ApplicationCommand[(pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId].BinaryCode);
-
- /* Perform the related L6470_AppCmdId */
- switch((pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId)
- {
- case L6470_NOP_ID:
- break;
- case L6470_SETPARAM_ID:
- /* Build the 1st bytes to transmit (PARAM) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address);
-
- /* The length, in byte, of this register (PARAM) is... */
- PARAMLengthBytes = L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].LengthByte;
-
- /* Build the others bytes to transmit (VALUE) */
- for (spibyte=1; spibyte<(PARAMLengthBytes+1); spibyte++)
- {
- *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(PARAMLengthBytes-spibyte)));
- }
- break;
- case L6470_GETPARAM_ID:
- /* Build the 1st bytes to transmit (PARAM) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address);
- break;
- case L6470_RUN_ID:
- /* Build the 1st bytes to transmit (DIR) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
-
- /* Build the others bytes to transmit (SPD) */
- for (spibyte=1; spibyte<(3+1); spibyte++)
- {
- *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
- }
- break;
- case L6470_STEPCLOCK_ID:
- /* Build the 1st bytes to transmit (DIR) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
- break;
- case L6470_MOVE_ID:
- /* Build the 1st bytes to transmit (DIR) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
-
- /* Build the others bytes to transmit (N_STEP) */
- for (spibyte=1; spibyte<(3+1); spibyte++)
- {
- *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
- }
- break;
- case L6470_GOTO_ID:
- /* Build the others bytes to transmit (ABS_POS) */
- for (spibyte=1; spibyte<(3+1); spibyte++)
- {
- *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p1) >> (8*(3-spibyte)));
- }
- break;
- case L6470_GOTODIR_ID:
- /* Build the 1st bytes to transmit (DIR) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
-
- /* Build the others bytes to transmit (ABS_POS) */
- for (spibyte=1; spibyte<(3+1); spibyte++)
- {
- *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
- }
- break;
- case L6470_GOUNTIL_ID:
- /* Build the 1st bytes to transmit (ACT) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3);
- /* Build the 1st bytes to transmit (DIR) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode);
-
- /* Build the others bytes to transmit (SPD) */
- for (spibyte=1; spibyte<(3+1); spibyte++)
- {
- *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p3) >> (8*(3-spibyte)));
- }
- break;
- case L6470_RELEASESW_ID:
- /* Build the 1st bytes to transmit (ACT) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3);
- /* Build the 1st bytes to transmit (DIR) */
- *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode);
- break;
- case L6470_GOHOME_ID:
- break;
- case L6470_GOMARK_ID:
- break;
- case L6470_RESETPOS_ID:
- break;
- case L6470_RESETDEVICE_ID:
- break;
- case L6470_SOFTSTOP_ID:
- break;
- case L6470_HARDSTOP_ID:
- break;
- case L6470_SOFTHIZ_ID:
- break;
- case L6470_HARDHIZ_ID:
- break;
- case L6470_GETSTATUS_ID:
- break;
- }
- }
-}
-
-/* End of L6470_Private_Functions */
-
-/**
- * @addtogroup L6470_Exported_Functions
- * @{
- */
-
-/**
- * @addtogroup L6470_Conversion_Functions
- * @brief The following functions act just on one driver inside the L6470
- * daisy chain. The command is immediately sent.
- * @{
- */
-
- /**
- * @brief Convert the absolute position as 2's complement format into the signed number.
- *
- * @param AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1].
- * @retval Position The position as signed number.
- */
-int32_t L6470::L6470_AbsPos_2_Position(uint32_t AbsPos)
-{
- if (AbsPos > L6470_MAX_POSITION)
- return (AbsPos - (L6470_POSITION_RANGE + 1));
- else
- return AbsPos;
-}
-
-/**
- * @brief Convert the position as signed number into absolute position as 2's complement format.
- *
- * @param Position The position as signed number.
- * @retval AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1].
- */
-uint32_t L6470::L6470_Position_2_AbsPos(int32_t Position)
-{
- if ((Position >= 0) && (Position <= L6470_MAX_POSITION))
- return Position;
- else
- {
- if ((Position >= L6470_MIN_POSITION) && (Position < 0))
- return (Position + (L6470_POSITION_RANGE + 1));
- else
- return (L6470_POSITION_RANGE + 1); // OVF
- }
-}
-
-/**
- * @brief Convert the SPEED register value into step/s.
- *
- * @param Speed The SPEED register value.
- * @retval step/s The speed as step/s.
- */
-float L6470::L6470_Speed_2_Step_s(uint32_t Speed)
-{
- return (Speed * ((float)14.9012e-3));
-}
-
-/**
- * @brief Convert the speed as step/s into a right value for SPEED register.
- *
- * @param step/s The speed as step/s.
- * @retval Speed The SPEED register value.
- */
-uint32_t L6470::L6470_Step_s_2_Speed(float Step_s)
-{
- if (Step_s <= (L6470_MAX_SPEED * ((float)14.9012e-3)))
- return (uint32_t)(Step_s / ((float)14.9012e-3));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the ACC register value into step/(s^2).
- *
- * @param Acc The ACC register value.
- * @retval step/(s^2) The acceleration as step/(s^2).
- */
-float L6470::L6470_Acc_2_Step_s2(uint16_t Acc)
-{
- if (Acc <= L6470_MAX_ACC)
- return (Acc * ((float)1.4552e1));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the acceleartion as step/(s^2) into a right value for ACC register.
- *
- * @param step/(s^2) The acceleration as step/(s^2).
- * @retval Acc The ACC register value.
- */
-uint16_t L6470::L6470_Step_s2_2_Acc(float Step_s2)
-{
- if (Step_s2 <= (L6470_MAX_ACC * ((float)1.4552e1)))
- return (uint16_t)(Step_s2 / ((float)1.4552e1));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the DEC register value into step/(s^2).
- *
- * @param Dec The DEC register value.
- * @retval step/(s^2) The deceleration as step/(s^2).
- */
-float L6470::L6470_Dec_2_Step_s2(uint16_t Dec)
-{
- if (Dec <= L6470_MAX_DEC)
- return (Dec * ((float)1.4552e1));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the deceleration as step/(s^2) into a right value for DEC register.
- *
- * @param step/(s^2) The deceleration as step/(s^2).
- * @retval Dec The DEC register value.
- */
-uint16_t L6470::L6470_Step_s2_2_Dec(float Step_s2)
-{
- if (Step_s2 <= (L6470_MAX_DEC * ((float)1.4552e1)))
- return (uint16_t)(Step_s2 / ((float)1.4552e1));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the MAX_SPEED register value into step/s.
- *
- * @param MaxSpeed The MAX_SPEED register value.
- * @retval step/s The max speed as step/s.
- */
-float L6470::L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed)
-{
- if (MaxSpeed <= L6470_MAX_MAX_SPEED)
- return (MaxSpeed * ((float)15.2588));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the max speed as step/s into a right value for MAX_SPEED register.
- *
- * @param step/s The max speed as step/s.
- * @retval MaxSpeed The MAX_SPEED register value.
- */
-uint16_t L6470::L6470_Step_s_2_MaxSpeed(float Step_s)
-{
- if (Step_s <= (L6470_MAX_MAX_SPEED * ((float)15.2588)))
- return (uint16_t)(Step_s / ((float)15.2588));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the MIN_SPEED register value into step/s.
- *
- * @param MinSpeed The MIN_SPEED register value.
- * @retval step/s The min speed as step/s.
- */
-float L6470::L6470_MinSpeed_2_Step_s(uint16_t MinSpeed)
-{
- if (MinSpeed <= L6470_MAX_MIN_SPEED)
- return (MinSpeed * ((float)238.4186e-3));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the min speed as step/s into a right value for MIN_SPEED register.
- *
- * @param step/s The min speed as step/s.
- * @retval MinSpeed The MIN_SPEED register value.
- */
-uint16_t L6470::L6470_Step_s_2_MinSpeed(float Step_s)
-{
- if (Step_s <= (L6470_MAX_MIN_SPEED * ((float)238.4186e-3)))
- return (uint16_t)(Step_s / ((float)238.4186e-3));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the FS_SPD register value into step/s.
- *
- * @param FsSpd The FS_SPD register value.
- * @retval step/s The full-step speed as step/s.
- */
-float L6470::L6470_FsSpd_2_Step_s(uint16_t FsSpd)
-{
- if (FsSpd <= L6470_MAX_FS_SPD)
- return ((FsSpd+0.5) * ((float)15.25));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the full-step speed as step/s into a right value for FS_SPD register.
- *
- * @param step/s The full-step speed as step/s.
- * @retval FsSpd The FS_SPD register value.
- */
-uint16_t L6470::L6470_Step_s_2_FsSpd(float Step_s)
-{
- if (Step_s <= ((L6470_MAX_FS_SPD+0.5) * ((float)15.25)))
- return (uint16_t)((float)(Step_s / ((float)15.25)) - (float)0.5);
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the INT_SPEED register value into step/s.
- *
- * @param IntSpeed The INT_SPEED register value.
- * @retval step/s The intersect speed as step/s.
- */
-float L6470::L6470_IntSpeed_2_Step_s(uint16_t IntSpeed)
-{
- if (IntSpeed <= L6470_MAX_INT_SPEED)
- return (IntSpeed * ((float)59.6046e-3));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
- *
- * @param step/s The full-step speed as step/s.
- * @retval FsSpd The FS_SPD register value.
- */
-uint16_t L6470::L6470_Step_s_2_IntSpeed(float Step_s)
-{
- if (Step_s <= (L6470_MAX_INT_SPEED * ((float)59.6046e-3)))
- return (uint16_t)(Step_s / ((float)59.6046e-3));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the ST_SLP register value into s/step.
- *
- * @param StartSlope The ST_SLP register value.
- * @retval s/step The start slope as s/step.
- */
-float L6470::L6470_StSlp_2_s_Step(uint8_t StSlp)
-{
-// if (StSlp <= L6470_MAX_ST_SLP)
- return (StSlp * ((float)1.5686e-5));
-// else
-// return 0; // Warning
-}
-
-/**
- * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
- *
- * @param step/s The full-step speed as step/s.
- * @retval FsSpd The FS_SPD register value.
- */
-uint8_t L6470::L6470_s_Step_2_StSlp(float s_Step)
-{
- if (s_Step <= (L6470_MAX_ST_SLP * ((float)1.5686e-5)))
- return (uint8_t)(s_Step / ((float)1.5686e-5));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the INT_SPEED register value into step/s.
- *
- * @param IntSpeed The INT_SPEED register value.
- * @retval step/s The intersect speed as step/s.
- */
-float L6470::L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc)
-{
-// if (FnSlpAcc <= L6470_MAX_FN_SLP_ACC)
- return (FnSlpAcc * ((float)1.5686e-5));
-// else
-// return 0; // Warning
-}
-
-/**
- * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
- *
- * @param step/s The full-step speed as step/s.
- * @retval FsSpd The FS_SPD register value.
- */
-uint8_t L6470::L6470_s_Step_2_FnSlpAcc(float s_Step)
-{
- if (s_Step <= (L6470_MAX_FN_SLP_ACC * ((float)1.5686e-5)))
- return (uint8_t)(s_Step / ((float)1.5686e-5));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the INT_SPEED register value into step/s.
- *
- * @param IntSpeed The INT_SPEED register value.
- * @retval step/s The intersect speed as step/s.
- */
-float L6470::L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec)
-{
-// if (FnSlpDec <= L6470_MAX_FN_SLP_DEC)
- return (FnSlpDec * ((float)1.5686e-5));
-// else
-// return 0; // Warning
-}
-
-/**
- * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
- *
- * @param step/s The full-step speed as step/s.
- * @retval FsSpd The FS_SPD register value.
- */
-uint8_t L6470::L6470_s_Step_2_FnSlpDec(float s_Step)
-{
- if (s_Step <= (L6470_MAX_FN_SLP_DEC * ((float)1.5686e-5)))
- return (uint8_t)(s_Step / ((float)1.5686e-5));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the OCD_TH register value into mA.
- *
- * @param OcdTh The OCD_TH register value.
- * @retval mA The overcurrent threshold as mA.
- */
-float L6470::L6470_OcdTh_2_mA(uint8_t OcdTh)
-{
- if (OcdTh <= L6470_MAX_OCD_TH)
- return ((OcdTh+1) * ((float)375));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the overcurrent threshold as mA into a right value for OCD_TH register.
- *
- * @param mA The overcurrent threshold as mA.
- * @retval OcdTh The OCD_TH register value.
- */
-uint8_t L6470::L6470_mA_2_OcdTh(float mA)
-{
- float result, decimal;
-
- if (mA <= ((L6470_MAX_OCD_TH+1) * ((float)375)))
- {
- result = (mA / ((float)375));
- decimal = result - (uint8_t)result;
-
- if (decimal < (float)0.5)
- return ((uint8_t)result - 1);
- else
- return ((uint8_t)result);
- }
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the STALL_TH register value into mA.
- *
- * @param StallTh The STALL_TH register value.
- * @retval mA The stall detection threshold as mA.
- */
-float L6470::L6470_StallTh_2_mA(uint8_t StallTh)
-{
- if (StallTh <= L6470_MAX_STALL_TH)
- return ((StallTh+1) * ((float)31.25));
- else
- return 0; // Warning
-}
-
-/**
- * @brief Convert the stall detection threshold as mA into a right value for STALL_TH register.
- *
- * @param mA The stall detection threshold as mA.
- * @retval StallTh The STALL_TH register value.
- */
-uint8_t L6470::L6470_mA_2_StallTh(float mA)
-{
- float result, decimal;
-
- if (mA <= ((L6470_MAX_STALL_TH+1) * ((float)31.25)))
- {
- result = (mA / ((float)31.25));
- decimal = result - (uint8_t)result;
-
- if (decimal < (float)0.5)
- return ((uint8_t)result - 1);
- else
- return ((uint8_t)result);
- }
- else
- return 0; // Warning
-}
-
-/* End of L6470_Conversion_Functions */
-
-/**
- * @addtogroup L6470_AppCMDs
- * @{
- */
-
-/**
- * @brief SetParam command sets the register value equal to a new value.
- *
- * @param L6470_RegId The identifier of the L6470 register to be addressed.
- * @param Value The new value.
- */
-void L6470::L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief GetParam command reads the register value.
- *
- * @param L6470_RegId The identifier of the L6470 register to be addressed.
- *
- * @retval ReceivedValue The register value.
- */
-uint32_t L6470::L6470_GetParam(eL6470_RegId_t L6470_RegId)
-{
- uint8_t ValueLengthByte;
- uint32_t ReceivedValue;
-
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-
- ValueLengthByte = L6470_Register[L6470_RegId].LengthByte;
-
- ReceivedValue = L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, ValueLengthByte);
-
- return ReceivedValue;
-}
-
-/**
- * @brief Run command produces a motion at fixed speed.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
- */
-void L6470::L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief StepClock command switches the device in Step-clock mode.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- */
-void L6470::L6470_StepClock(eL6470_DirId_t L6470_DirId)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief Move command produces a motion of N_STEP microsteps.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param N_Step The number of microsteps.
- */
-void L6470::L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief GoTo command produces a motion to ABS_POS absolute position through the shortest path.
- *
- * @param AbsPos The target absolute position.
- */
-void L6470::L6470_GoTo(uint32_t AbsPos)
-{
- if (AbsPos <= L6470_POSITION_RANGE)
- {
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
- }
-}
-
-/**
- * @brief GoTo_DIR command produces a motion to ABS_POS absolute position imposing a direction.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param AbsPos The target absolute position.
- */
-void L6470::L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos)
-{
- if (AbsPos <= L6470_POSITION_RANGE)
- {
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
- }
-}
-
-/**
- * @brief GoUntil command produces a motion at fixed speed imposing a direction
- * until an external switch turn-on event occurs.
- *
- * @param L6470_ActId The identifier of the L6470 action about the absolute position.
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
- */
-void L6470::L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief ReleaseSW command produces a motion at minimum speed imposing a direction
- * until SW is released.
- *
- * @param L6470_ActId The identifier of the L6470 action about the absolute position.
- * @param L6470_DirId The identifier of the L6470 motion direction.
- */
-void L6470::L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief GoHome command produces a motion to the HOME position (zero position)
- * via the shortest path.
- *
- */
-void L6470::L6470_GoHome(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief GoMark command produces a motion to the MARK position performing the
- * minimum path.
- *
- */
-void L6470::L6470_GoMark(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief ResetPos command resets the ABS_POS register to zero.
- *
- */
-void L6470::L6470_ResetPos(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief ResetDevice command resets the device to power-up conditions.
- *
- */
-void L6470::L6470_ResetDevice(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief SoftStop command causes an immediate deceleration to zero speed and
- * a consequent motor stop; the deceleration value used is the one stored
- * in the DEC register.
- *
- */
-void L6470::L6470_SoftStop(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief HardStop command causes an immediate motor stop with infinite deceleration.
- *
- */
-void L6470::L6470_HardStop(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief SoftHiZ command disables the power bridges (high impedance state)
- * after a deceleration to zero; the deceleration value used is the one
- * stored in the DEC register.
- *
- */
-void L6470::L6470_SoftHiZ(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief HardHiZ command immediately disables the power bridges (high impedance state).
- *
- */
-void L6470::L6470_HardHiZ(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief GetStatus command returns the STATUS register value.
- *
- *
- * @retval ReceivedValue The register value.
- */
-uint16_t L6470::L6470_GetStatus(void)
-{
- uint16_t ReceivedValue;
-
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0);
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-
- ReceivedValue = (uint16_t)L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, 2);
-
- return ReceivedValue;
-}
-
-/* End of L6470_AppCMDs */
-
-/**
- * @addtogroup L6470_AppCMDs_ToBePrepared
- * @{
- */
-
-/**
- * @brief Prepare to send @ref L6470_SetParam command.
- *
- * @param L6470_RegId The identifier of the L6470 register to be addressed.
- * @param Value The new value.
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_GetParam command.
- *
- * @param L6470_Id The L6470 identifier inside the daisy chain.
- * @param L6470_RegId The identifier of the L6470 register to be addressed.
- *
- * @retval ReceivedValue The register value.
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_Run command.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_StepClock command.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_Move command.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param N_Step The number of microsteps.
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_GoTo command.
- *
- * @param AbsPos The target absolute position.
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareGoTo(uint32_t AbsPos)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_GoToDIR command.
- *
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param AbsPos The target absolute position.
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_GoUntil command.
- *
- * @param L6470_ActId The identifier of the L6470 action about the absolute position.
- * @param L6470_DirId The identifier of the L6470 motion direction.
- * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed);
-}
-
-/**
- * @brief Prepare to send @ref L6470_ReleaseSW.
- *
- * @param L6470_ActId The identifier of the L6470 action about the absolute position.
- * @param L6470_DirId The identifier of the L6470 motion direction.
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_GoHome command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareGoHome(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_GoMark command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareGoMark(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_ResetPos command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareResetPos(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_ResetDevice command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareResetDevice(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_SoftStop command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareSoftStop(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_HardStop command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareHardStop(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_SoftHiZ command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareSoftHiZ(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_HardHiZ command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareHardHiZ(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0);
-}
-
-/**
- * @brief Prepare to send @ref L6470_GetStatus command.
- *
- *
- * @note This function will properly fill the right column of the L6470_AppCmdPkg.
- * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
- */
-void L6470::L6470_PrepareGetStatus(void)
-{
- L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0);
-}
-
-/* End of L6470_AppCMDs_ToBePrepared */
-
-/**
- * @brief Send via SPI the command stored inside the L6470_AppCmdPkg to the
- * L6470 daisy chain.
- *
- * @retval (uint8_t*)data->L6470_DaisyChainSpiRxStruct The pointer to the structure
- * containing returned values from each L6470 of the daisy chain for each
- * sent SPI data.
- */
-uint8_t* L6470::L6470_PerformPreparedApplicationCommand(void)
-{
- L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
- L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
-
- return (uint8_t*)(L6470_DaisyChainSpiRxStruct);
-}
-
-/**
- * @brief Send command to the L6470 daisy chain via SPI
- * @param pL6470_DaisyChainSpiTxStruct Pointer to the matrix array of bytes to be sent to the daisy chain L6470
- * @param pL6470_DaisyChainSpiRxStruct Pointer to the matrix array of bytes to be received from the daisy chain L6470
- */
-void L6470::L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct)
-{
- uint8_t spibyte;
-
- L6470_DaisyChain_HalfPrepared = ZERO_F;
-
- /* Send all command bytes via SPI */
- for(spibyte=0; spibyte < L6470MAXSPICMDBYTESIZE; spibyte++)
- {
- /* Send the command via SPI */
- L6470_SPI_Communication((pL6470_DaisyChainSpiTxStruct+(spibyte * L6470DAISYCHAINSIZE)), (pL6470_DaisyChainSpiRxStruct+(spibyte * L6470DAISYCHAINSIZE)), L6470DAISYCHAINSIZE, 10);
-
- //_DELAY(TDISCS);
- uint8_t delay_cnt;
- for (delay_cnt=0; delay_cnt<20; delay_cnt++) __NOP(); //!<Simply deselect time delay for SPI nCS
- }
-}
-
-/**
- * @brief Extracts the data returned by the L6470 from the matrix that
- * contains the received SPI data.
- * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
- * @param pL6470_DaisyChainSpiRxStruct uint8_t-pointer to the matrix that
- * contains the received data by SPI from the L6470 daisy chain.
- * @param LengthByte The number of bytes about the received value.
- */
-uint32_t L6470::L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte)
-{
- uint32_t value;
- uint8_t i;
-
- value = 0x000000;
- for (i=1; i<=(L6470MAXSPICMDBYTESIZE-1); i++)
- {
- value |= (*(pL6470_DaisyChainSpiRxStruct+(i*L6470DAISYCHAINSIZE)+L6470_Id))<<((LengthByte-i)*8);
- }
-
- return value;
-}
-
-/**
- * @brief Check the state of a flag inside the L6470 STATUS register.
- *
- * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
- * @param L6470_StatusRegisterFlagId The identifier of the L6470 STATUS flag to be checked.
- *
- * @retval state The flag state.
- */
-
-uint8_t L6470::L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId)
-{
- uint8_t state = 0;
-
- *((uint16_t*)pL6470_StatusRegister) = L6470_GetParam(L6470_STATUS_ID);
-
- switch(L6470_StatusRegisterFlagId)
- {
- case HiZ_ID:
- state = pL6470_StatusRegister->HiZ;
- break;
- case BUSY_ID:
- state = pL6470_StatusRegister->BUSY;
- break;
- case SW_F_ID:
- state = pL6470_StatusRegister->SW_F;
- break;
- case SW_EVN_ID:
- state = pL6470_StatusRegister->SW_EVN;
- break;
- case DIR_ID:
- state = pL6470_StatusRegister->DIR;
- break;
- case MOT_STATUS_ID:
- state = pL6470_StatusRegister->MOT_STATUS;
- break;
- case NOTPERF_CMD_ID:
- state = pL6470_StatusRegister->NOTPERF_CMD;
- break;
- case WRONG_CMD_ID:
- state = pL6470_StatusRegister->WRONG_CMD;
- break;
- case UVLO_ID:
- state = pL6470_StatusRegister->UVLO;
- break;
- case TH_WRN_ID:
- state = pL6470_StatusRegister->TH_WRN;
- break;
- case TH_SD_ID:
- state = pL6470_StatusRegister->TH_SD;
- break;
- case OCD_ID:
- state = pL6470_StatusRegister->OCD;
- break;
- case STEP_LOSS_A_ID:
- state = pL6470_StatusRegister->STEP_LOSS_A;
- break;
- case STEP_LOSS_B_ID:
- state = pL6470_StatusRegister->STEP_LOSS_B;
- break;
- case SCK_MOD_ID:
- state = pL6470_StatusRegister->SCK_MOD;
- break;
- }
-
- return state;
-}
-
-/**
- * @brief Return the mnemonic name for the L6470 register.
- * @param id The identifier of the L6470 register.
- */
-uint8_t *L6470::L6470_GetRegisterName(uint8_t id)
-{
- if (id < L6470REGIDSIZE)
- {
- return (uint8_t*)L6470_Register[id].Name;
- }
- else
- {
- return NULL;
- }
-}
-
-/**
- * @brief Configures the L6470 registers.
- * @param init The pointer to the initialization structure.
- */
-status_t L6470::L6470_Config(void *init)
-{
- /* Disable the L6470. */
- L6470_DISABLE();
-
- /* Enable the L6470. */
- L6470_ENABLE();
-
- /* Reset devices. */
- ResetDevice();
-
- /* Reset Status Register flags. */
- GetStatus();
-
- /* Prepare the 'Register' field of StepperMotorDriverHandle */
- L6470_init_t *MotorParameterData = (L6470_init_t *) init;
- StepperMotorRegister.ACC = L6470_Step_s2_2_Acc(MotorParameterData->acc);
- StepperMotorRegister.DEC = L6470_Step_s2_2_Dec(MotorParameterData->dec);
- StepperMotorRegister.MAX_SPEED = L6470_Step_s_2_MaxSpeed(MotorParameterData->maxspeed);
- StepperMotorRegister.MIN_SPEED = L6470_Step_s_2_MinSpeed(MotorParameterData->minspeed);
- StepperMotorRegister.FS_SPD = L6470_Step_s_2_FsSpd(MotorParameterData->fsspd);
- StepperMotorRegister.KVAL_HOLD = (uint8_t)((float)((float)(MotorParameterData->kvalhold * 256) / (MotorParameterData->motorvoltage)));
- StepperMotorRegister.KVAL_RUN = (uint8_t)((float)((float)(MotorParameterData->kvalrun * 256) / (MotorParameterData->motorvoltage)));
- StepperMotorRegister.KVAL_ACC = (uint8_t)((float)((float)(MotorParameterData->kvalacc * 256) / (MotorParameterData->motorvoltage)));
- StepperMotorRegister.KVAL_DEC = (uint8_t)((float)((float)(MotorParameterData->kvaldec * 256) / (MotorParameterData->motorvoltage)));
- StepperMotorRegister.INT_SPEED = L6470_Step_s_2_IntSpeed(MotorParameterData->intspeed);
- StepperMotorRegister.ST_SLP = L6470_s_Step_2_StSlp(MotorParameterData->stslp);
- StepperMotorRegister.FN_SLP_ACC = L6470_s_Step_2_FnSlpAcc(MotorParameterData->fnslpacc);
- StepperMotorRegister.FN_SLP_DEC = L6470_s_Step_2_FnSlpDec(MotorParameterData->fnslpdec);
- StepperMotorRegister.K_THERM = MotorParameterData->kterm;
- StepperMotorRegister.OCD_TH = L6470_mA_2_OcdTh(MotorParameterData->ocdth);
- StepperMotorRegister.STALL_TH = L6470_mA_2_StallTh(MotorParameterData->stallth);
- StepperMotorRegister.ALARM_EN = MotorParameterData->alarmen;
- StepperMotorRegister.CONFIG = MotorParameterData->config;
- StepperMotorRegister.STEP_MODE = MotorParameterData->step_sel;
-
- /* Write the L6470 registers with the prepared data */
- L6470_SetParam(L6470_ACC_ID, StepperMotorRegister.ACC);
- L6470_SetParam(L6470_DEC_ID, StepperMotorRegister.DEC);
- L6470_SetParam(L6470_MAX_SPEED_ID, StepperMotorRegister.MAX_SPEED);
- L6470_SetParam(L6470_MIN_SPEED_ID, StepperMotorRegister.MIN_SPEED);
- L6470_SetParam(L6470_FS_SPD_ID, StepperMotorRegister.FS_SPD);
- L6470_SetParam(L6470_KVAL_HOLD_ID, StepperMotorRegister.KVAL_HOLD);
- L6470_SetParam(L6470_KVAL_RUN_ID, StepperMotorRegister.KVAL_RUN);
- L6470_SetParam(L6470_KVAL_ACC_ID, StepperMotorRegister.KVAL_ACC);
- L6470_SetParam(L6470_KVAL_DEC_ID, StepperMotorRegister.KVAL_DEC);
- L6470_SetParam(L6470_INT_SPEED_ID, StepperMotorRegister.INT_SPEED);
- L6470_SetParam(L6470_ST_SLP_ID, StepperMotorRegister.ST_SLP);
- L6470_SetParam(L6470_FN_SLP_ACC_ID, StepperMotorRegister.FN_SLP_ACC);
- L6470_SetParam(L6470_FN_SLP_DEC_ID, StepperMotorRegister.FN_SLP_DEC);
- L6470_SetParam(L6470_K_THERM_ID, StepperMotorRegister.K_THERM);
- L6470_SetParam(L6470_OCD_TH_ID, StepperMotorRegister.OCD_TH);
- L6470_SetParam(L6470_STALL_TH_ID, StepperMotorRegister.STALL_TH);
- L6470_SetParam(L6470_ALARM_EN_ID, StepperMotorRegister.ALARM_EN);
- L6470_SetParam(L6470_CONFIG_ID, StepperMotorRegister.CONFIG);
- if (!SetStepMode((StepperMotor::step_mode_t) StepperMotorRegister.STEP_MODE))
- return COMPONENT_ERROR;
-
- return COMPONENT_OK;
-}
-
-/* End of L6470_Exported_Functions */
-
-/* End of L6470 */
-
-/* End of Components */
-
-/* End of BSP */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Components/l6470/L6470_def.h Fri Mar 10 11:09:21 2017 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,315 +0,0 @@
-/**
- ******************************************************************************
- * @file L6470_def.h
- * @date 01/10/2014 12:00:00
- * @brief This file contains definitions, exported variables and function
- * prototypes related to the L6470.
- ******************************************************************************
- *
- * COPYRIGHT(c) 2014 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-
-#ifndef __L6470_H
-#define __L6470_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-
-/* Includes ------------------------------------------------------------------*/
-
-#include "../Common/microstepping_motor_def.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;
-
-/**
- * @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.
- */
-/* 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
-{
- 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;
-
-/**
- * @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;
-
-
-/* Functions -----------------------------------------------------------------*/
-
-/** @addtogroup BSP
- * @{
- */
-
-/** @addtogroup Components
- * @{
- */
-
-/** @addtogroup L6470
- * @{
- */
-
-/** @defgroup L6470_Imported_Functions L6470_Imported_Functions
- * @{
- */
-
-/* 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);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __L6470_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Components/l6470/l6470.h Fri Mar 10 11:09:21 2017 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1584 +0,0 @@
-/**
- ******************************************************************************
- * @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
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-
-/* 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_CLASS_H
-#define __L6470_CLASS_H
-
-
-/* Includes ------------------------------------------------------------------*/
-
-/* 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"
-
-
-/* Classes -------------------------------------------------------------------*/
-
-/**
- * @brief Class representing a L6470 component.
- */
-class L6470 : public StepperMotor
-{
-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 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) {}
-
-
- /*** 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);
- }
-
- /**
- * @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();
- }
-
- /**
- * @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;
- }
-
- /**
- * @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;
- }
-
- /**
- * @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;
- }
-
- /**
- * @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);
-
- 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 ***/
-
- /* 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****/
--- a/ST_INTERFACES.lib Fri Mar 10 11:09:21 2017 +0100 +++ b/ST_INTERFACES.lib Fri Mar 10 15:23:54 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#a7810e7acf8d +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#8f70f7159316
--- a/X_NUCLEO_COMMON.lib Fri Mar 10 11:09:21 2017 +0100 +++ b/X_NUCLEO_COMMON.lib Fri Mar 10 15:23:54 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#216930edb6b7 +https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#12be3dfc15fd

X-NUCLEO-IHM02A1 Two Axis Stepper Motor Driver