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 0:92706998571a, committed 2015-11-20
- Comitter:
- Davidroid
- Date:
- Fri Nov 20 18:07:45 2015 +0000
- Child:
- 1:b78dab6d2c58
- Commit message:
- Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the the L6470 component.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.cpp Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,270 @@
+/**
+ ******************************************************************************
+ * @file x_nucleo_ihm02a1_class.cpp
+ * @author AST / Software Platforms and Cloud
+ * @version V1.0
+ * @date November 3rd, 2015
+ * @brief Implementation file for the X_NUCLEO_IHM02A1 expansion board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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 -----------------------------------------------*/
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/* ACTION 1 ------------------------------------------------------------------*
+ * Include here platform specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "mbed.h"
+#include "DevSPI.h"
+/* ACTION 2 ------------------------------------------------------------------*
+ * Include here expansion board specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "x_nucleo_ihm02a1_class.h"
+
+
+/* Static variables ----------------------------------------------------------*/
+
+/* Singleton instance of X_NUCLEO_IHM02A1 class. */
+X_NUCLEO_IHM02A1 *X_NUCLEO_IHM02A1::_instance;
+
+/* Number of instantiated expansion boards. */
+uint8_t X_NUCLEO_IHM02A1::number_of_boards = 0;
+
+/**
+ * @brief This array contains the initial parameters for the motors that are
+ * linked with each L6470 mounted on each stacked X-NUCLEO-IHM02A1.
+ */
+const MICROSTEPPING_MOTOR_InitTypeDef X_NUCLEO_IHM02A1::MotorParameterInitData[EXPBRD_MOUNTED_NR_MAX][L6470DAISYCHAINSIZE] =
+{
+ {
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ },
+ {
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ },
+ {
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ },
+ {
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ {
+ 9.0, 400, 1.7, 3.06, 300.0, 500.0, 500.0, 400.0, 0.0, 602.7, 3.06, 3.06,\
+ 3.06, 3.06, 61.52, 392.1569e-6, 643.1372e-6, 643.1372e-6, 0,\
+ 3.06*1000*1.10, 3.06*1000*1.00, MICROSTEP_1_128, 0xFF, 0x2E88
+ },
+ },
+};
+
+
+/* Methods -------------------------------------------------------------------*/
+
+/**
+ * @brief Constructor.
+ * @param flag_irq pin name of the FLAG 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.
+ */
+X_NUCLEO_IHM02A1::X_NUCLEO_IHM02A1(PinName flag_irq, PinName standby_reset, PinName ssel, DevSPI *spi) : dev_spi(spi)
+{
+ /* Instantiating the components. */
+ /* ACTION 3 --------------------------------------------------------------*
+ * Instantiate here the expansion board's components. *
+ * *
+ * Example: *
+ * component_1 = new COMPONENT_1(COMPONENT_1_SPI_SSEL, *dev_spi); *
+ * component_2 = new COMPONENT_2(COMPONENT_2_SPI_SSEL, *dev_spi); *
+ *------------------------------------------------------------------------*/
+ X_NUCLEO_IHM02A1_Id = number_of_boards++;
+ l6470_0 = new L6470(flag_irq, standby_reset, ssel, *dev_spi);
+ l6470_1 = new L6470(flag_irq, standby_reset, ssel, *dev_spi);
+}
+
+/**
+ * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
+ * @param flag_irq pin name of the FLAG 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.
+ * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
+ */
+X_NUCLEO_IHM02A1 *X_NUCLEO_IHM02A1::Instance(PinName flag_irq, PinName standby_reset, PinName ssel, DevSPI *spi)
+{
+ if (_instance == NULL)
+ {
+ /* SPI communication. */
+ if (spi == NULL)
+ spi = new DevSPI(X_NUCLEO_IHM02A1_PIN_SPI_MOSI, X_NUCLEO_IHM02A1_PIN_SPI_MISO, X_NUCLEO_IHM02A1_PIN_SPI_SCLK);
+
+ /* Instantiating the board. */
+ _instance = new X_NUCLEO_IHM02A1(flag_irq, standby_reset, ssel, spi);
+
+ /* Initializing the components. */
+ if (!_instance->Init())
+ error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
+ }
+
+ return _instance;
+}
+
+/**
+ * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
+ * @param flag_irq pin name of the FLAG 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 mosi pin name of the MOSI pin of the SPI device to be used for communication.
+ * @param miso pin name of the MISO pin of the SPI device to be used for communication.
+ * @param sclk pin name of the SCLK pin of the SPI device to be used for communication.
+ * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
+ */
+X_NUCLEO_IHM02A1 *X_NUCLEO_IHM02A1::Instance(PinName flag_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk)
+{
+ if (_instance == NULL)
+ {
+ /* SPI communication. */
+ DevSPI *spi = new DevSPI(mosi, miso, sclk);
+
+ /* Instantiating the board. */
+ _instance = new X_NUCLEO_IHM02A1(flag_irq, standby_reset, ssel, spi);
+
+ /* Initializing the components. */
+ if (!_instance->Init())
+ error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
+ }
+
+ return _instance;
+}
+
+/**
+ * @brief Initializing the X_NUCLEO_IHM02A1 board.
+ * @retval true if initialization is successful, false otherwise.
+ */
+bool X_NUCLEO_IHM02A1::Init(void)
+{
+ /* Initializing the components. */
+ /* ACTION 4 --------------------------------------------------------------*
+ * Initialize here the expansion board's components. *
+ * *
+ * Example: *
+ * return (Init_COMPONENT_1() && Init_COMPONENT_2()); *
+ *------------------------------------------------------------------------*/
+ return (Init_L6470_0() && Init_L6470_1());
+}
+
+/* ACTION 5 ------------------------------------------------------------------*
+ * Implement here an initialization method for each expansion board's *
+ * component. *
+ * *
+ * Example: *
+ * bool EXPANSION_BOARD::Init_COMPONENT_1(void) *
+ * { *
+ * // Verifying identity. *
+ * uint8_t id = 0; *
+ * int ret = component_1->ReadID(&id); *
+ * if ((ret != COMPONENT_OK) || (id != I_AM_COMPONENT_1)) *
+ * { *
+ * delete component_1; *
+ * component_1 = NULL; *
+ * return true; *
+ * } *
+ * *
+ * // Configuration. *
+ * INTERFACE_InitTypeDef InitStructure; *
+ * InitStructure.Property_1 = COMPONENT_1_PROPERY_1_INIT; *
+ * InitStructure.Property_N = COMPONENT_1_PROPERY_N_INIT; *
+ * *
+ * // Initialization. *
+ * if (component_1->Init(&InitStructure) != COMPONENT_OK) *
+ * return false; *
+ * *
+ * return true; *
+ * } *
+ *----------------------------------------------------------------------------*/
+/**
+ * @brief Initialize the L6470 component.
+ * @retval true if initialization is successful, false otherwise.
+ */
+bool X_NUCLEO_IHM02A1::Init_L6470_0(void)
+{
+ /* Initialization. */
+ if (l6470_0->Init((void *) &MotorParameterInitData[X_NUCLEO_IHM02A1_Id][0]) != COMPONENT_OK)
+ return false;
+
+ return true;
+}
+
+/**
+ * @brief Initialize the L6470 component.
+ * @retval true if initialization is successful, false otherwise.
+ */
+bool X_NUCLEO_IHM02A1::Init_L6470_1(void)
+{
+ /* Initialization. */
+ if (l6470_1->Init((void *) &MotorParameterInitData[X_NUCLEO_IHM02A1_Id][1]) != COMPONENT_OK)
+ return false;
+
+ return true;
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.h Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,182 @@
+/**
+ ******************************************************************************
+ * @file x_nucleo_ihm02a1_class.h
+ * @author AST / Software Platforms and Cloud
+ * @version V1.0
+ * @date November 3rd, 2015
+ * @brief Class header file for the X_NUCLEO_IHM02A1 expansion board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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 -----------------------------------------------*/
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __X_NUCLEO_IHM02A1_CLASS_H
+#define __X_NUCLEO_IHM02A1_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/* ACTION 1 ------------------------------------------------------------------*
+ * Include here platform specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "mbed.h"
+#include "DevSPI.h"
+/* ACTION 2 ------------------------------------------------------------------*
+ * Include here expansion board specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "x_nucleo_ihm02a1_config.h"
+/* ACTION 3 ------------------------------------------------------------------*
+ * Include here expansion board's components' header files. *
+ * *
+ * Example: *
+ * #include "component_1_class.h" *
+ * #include "component_2_class.h" *
+ *----------------------------------------------------------------------------*/
+#include "l6470_class.h"
+
+
+/* Classes -------------------------------------------------------------------*/
+
+/** Class representing a X_NUCLEO_IHM02A1 board.
+ */
+class X_NUCLEO_IHM02A1
+{
+public:
+
+ /*** Instance, Initialization and Destructor Methods ***/
+
+ /**
+ * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
+ * @param flag_irq pin name of the FLAG 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.
+ * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
+ */
+ static X_NUCLEO_IHM02A1 *Instance(PinName flag_irq, PinName standby_reset, PinName ssel, DevSPI *spi = NULL);
+
+ /**
+ * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
+ * @param flag_irq pin name of the FLAG 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 mosi pin name of the MOSI pin of the SPI device to be used for communication.
+ * @param miso pin name of the MISO pin of the SPI device to be used for communication.
+ * @param sclk pin name of the SCLK pin of the SPI device to be used for communication.
+ * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
+ */
+ static X_NUCLEO_IHM02A1 *Instance(PinName flag_irq, PinName standby_reset, PinName ssel, PinName miso, PinName mosi, PinName sclk);
+
+ /**
+ * @brief Initializing the X_NUCLEO_IHM02A1 board.
+ * @retval true if initialization is successful, false otherwise.
+ */
+ bool Init(void);
+
+ /**
+ * @brief Destructor.
+ */
+ ~X_NUCLEO_IHM02A1(void) {}
+
+
+ /*** Public Expansion Board Related Attributes ***/
+
+ /* ACTION 4 --------------------------------------------------------------*
+ * Declare here a public attribute for each expansion board's component. *
+ * You will have to call these attributes' public methods within your *
+ * main program. *
+ * *
+ * Example: *
+ * COMPONENT_1 *component_1; *
+ * COMPONENT_2 *component_2; *
+ *------------------------------------------------------------------------*/
+ L6470 *l6470_0;
+ L6470 *l6470_1;
+
+ /* Static data. */
+ static const MICROSTEPPING_MOTOR_InitTypeDef MotorParameterInitData[EXPBRD_MOUNTED_NR_MAX][L6470DAISYCHAINSIZE];
+
+
+protected:
+
+ /*** Protected Constructor Method ***/
+
+ /**
+ * @brief Constructor.
+ * @param flag_irq pin name of the FLAG 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.
+ */
+ X_NUCLEO_IHM02A1(PinName flag_irq, PinName standby_reset, PinName ssel, DevSPI *spi);
+
+
+ /*** Protected Expansion Board Related Initialization Methods ***/
+
+ /* ACTION 5 --------------------------------------------------------------*
+ * Declare here a protected initialization method for each expansion *
+ * board's component. *
+ * *
+ * Example: *
+ * bool Init_COMPONENT_1(void); *
+ * bool Init_COMPONENT_2(void); *
+ *------------------------------------------------------------------------*/
+ bool Init_L6470_0(void);
+ bool Init_L6470_1(void);
+
+
+ /*** Component's Instance Variables ***/
+
+ /* Singleton instance of X_NUCLEO_IHM02A1 class. */
+ static X_NUCLEO_IHM02A1 *_instance;
+
+ /* IO Device. */
+ DevSPI *dev_spi;
+
+ /* Data. */
+ /* ACTION 11 -------------------------------------------------------------*
+ * Declare here the component's data, one variable per line. *
+ * *
+ * Example: *
+ * uint8_t ExpansionBoard_Id; *
+ *------------------------------------------------------------------------*/
+ uint8_t X_NUCLEO_IHM02A1_Id;
+
+ /* Static data. */
+ static uint8_t number_of_boards;
+};
+
+#endif // __X_NUCLEO_IHM02A1_CLASS_H
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BSP/x_nucleo_ihm02a1_config.h Fri Nov 20 18:07:45 2015 +0000 @@ -0,0 +1,81 @@ +/** + ****************************************************************************** + * @file x_nucleo_ihm02a1_config.h + * @author AST / Software Platforms and Cloud + * @version V1.0 + * @date November 3rd, 2015 + * @brief Configuration header file for the X_NUCLEO_IHM02A1 expansion board. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * 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 -----------------------------------------------*/ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __X_NUCLEO_IHM02A1_CONFIG_H +#define __X_NUCLEO_IHM02A1_CONFIG_H + + +/* Definitions ---------------------------------------------------------------*/ + +/* ACTION --------------------------------------------------------------------* + * Specify here a configuration for I/O and interrupts' pins. * + * * + * Example: * + * // I2C. * + * #define EXPANSION_BOARD_PIN_I2C_SCL (D15) * + * #define EXPANSION_BOARD_PIN_I2C_SDA (D14) * + * * + * // SPI. * + * #define EXPANSION_BOARD_PIN_SPI_MOSI (D11) * + * #define EXPANSION_BOARD_PIN_SPI_MISO (D12) * + * #define EXPANSION_BOARD_PIN_SPI_SCLK (D13) * + * * + * // Interrupts. * + * #define EXPANSION_BOARD_PIN_INT_1 (A2) * + *----------------------------------------------------------------------------*/ +/* I2C. */ +#define X_NUCLEO_IHM02A1_PIN_I2C_SCL (D15) +#define X_NUCLEO_IHM02A1_PIN_I2C_SDA (D14) + +/* SPI. */ +#define X_NUCLEO_IHM02A1_PIN_SPI_MOSI (D11) +#define X_NUCLEO_IHM02A1_PIN_SPI_MISO (D12) +#define X_NUCLEO_IHM02A1_PIN_SPI_SCLK (D13) + +/* Interrupts. */ +#define X_NUCLEO_IHM02A1_PIN_INT_1 (A2) + +/* Maximum number of mounted "X-NUCLEO-IHM02A1" Expansion Boards. */ +#define EXPBRD_MOUNTED_NR_MAX (4) + +#endif // __X_NUCLEO_IHM02A1_CONFIG_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Common/component.h Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,91 @@
+/**
+ ******************************************************************************
+ * @file component.h
+ * @author AST
+ * @version V1.0.0
+ * @date 1 April 2015
+ * @brief Generic header file containing a generic component's definitions
+ * and I/O functions.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Prevent recursive inclusion -----------------------------------------------*/
+
+#ifndef __COMPONENT_H__
+#define __COMPONENT_H__
+
+
+/* Types ---------------------------------------------------------------------*/
+
+/**
+ * @brief Component's Context structure definition.
+ */
+typedef struct
+{
+ /* Identity. */
+ uint8_t who_am_i;
+
+ /* ACTION ----------------------------------------------------------------*/
+ /* There should be only a unique identifier for each component, which */
+ /* should be the "who_am_i" parameter, hence this parameter is optional. */
+ /* -----------------------------------------------------------------------*/
+ /* Type. */
+ uint8_t type;
+
+ /* Configuration. */
+ uint8_t address;
+
+ /* Pointer to the Data. */
+ void *pData;
+
+ /* Pointer to the Virtual Table. */
+ void *pVTable;
+
+ /* ACTION ----------------------------------------------------------------*/
+ /* There should be only a unique virtual table for each component, which */
+ /* should be the "pVTable" parameter, hence this parameter is optional. */
+ /* -----------------------------------------------------------------------*/
+ /* Pointer to the Extended Virtual Table. */
+ void *pExtVTable;
+} DrvContextTypeDef;
+
+/**
+ * @brief Component's Status enumerator definition.
+ */
+typedef enum
+{
+ COMPONENT_OK = 0,
+ COMPONENT_ERROR,
+ COMPONENT_TIMEOUT,
+ COMPONENT_NOT_IMPLEMENTED
+} DrvStatusTypeDef;
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Common/microstepping_motor.h Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,507 @@
+/**
+ ******************************************************************************
+ * @file microstepping_motor.h
+ * @author IPD SYSTEM LAB & TECH MKTG
+ * @version V0.0.1
+ * @date 04-June-2015
+ * @brief This file contains all the functions prototypes for the microstepping
+ * motor driver with motion engine.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * 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 __MICROSTEPPINGMOTOR_H
+#define __MICROSTEPPINGMOTOR_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdint.h>
+#include "component.h"
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @defgroup MicrosteppingMotorDriver
+ * @{
+ */
+
+/** @defgroup StepperMotorExportedTypes
+ * @{
+ */
+
+/**
+ * @brief The L6470 Registers Identifiers.
+ */
+typedef enum {
+ L6470_ABS_POS_ID = 0, //!< Current position
+ L6470_EL_POS_ID, //!< Electrical position
+ L6470_MARK_ID, //!< Mark position
+ L6470_SPEED_ID, //!< Current speed
+ L6470_ACC_ID, //!< Acceleration
+ L6470_DEC_ID, //!< Deceleration
+ L6470_MAX_SPEED_ID, //!< Maximum speed
+ L6470_MIN_SPEED_ID, //!< Minimum speed
+ L6470_FS_SPD_ID, //!< Full-step speed
+ L6470_KVAL_HOLD_ID, //!< Holding KVAL
+ L6470_KVAL_RUN_ID, //!< Constant speed KVAL
+ L6470_KVAL_ACC_ID, //!< Acceleration starting KVAL
+ L6470_KVAL_DEC_ID, //!< Deceleration starting KVAL
+ L6470_INT_SPEED_ID, //!< Intersect speed
+ L6470_ST_SLP_ID, //!< Start slope
+ L6470_FN_SLP_ACC_ID, //!< Acceleration final slope
+ L6470_FN_SLP_DEC_ID, //!< Deceleration final slope
+ L6470_K_THERM_ID, //!< Thermal compensation factor
+ L6470_ADC_OUT_ID, //!< ADC output, (the reset value is according to startup conditions)
+ L6470_OCD_TH_ID, //!< OCD threshold
+ L6470_STALL_TH_ID, //!< STALL threshold
+ L6470_STEP_MODE_ID, //!< Step mode
+ L6470_ALARM_EN_ID, //!< Alarm enable
+ L6470_CONFIG_ID, //!< IC configuration
+ L6470_STATUS_ID //!< Status, (the reset value is according to startup conditions)
+} eL6470_RegId_t;
+
+/**
+ * @brief The L6470 Application Commands Identifiers.
+ */
+typedef enum {
+ L6470_NOP_ID = 0, //!< Nothing
+ L6470_SETPARAM_ID, //!< Writes VALUE in PARAM register
+ L6470_GETPARAM_ID, //!< Returns the stored value in PARAM register
+ L6470_RUN_ID, //!< Sets the target speed and the motor direction
+ L6470_STEPCLOCK_ID, //!< Puts the device into Step-clock mode and imposes DIR direction
+ L6470_MOVE_ID, //!< Makes N_STEP (micro)steps in DIR direction (Not performable when motor is running)
+ L6470_GOTO_ID, //!< Brings motor into ABS_POS position (minimum path)
+ L6470_GOTODIR_ID, //!< Brings motor into ABS_POS position forcing DIR direction
+ L6470_GOUNTIL_ID, //!< Performs a motion in DIR direction with speed SPD until SW is closed, the ACT action is executed then a SoftStop takes place
+ L6470_RELEASESW_ID, //!< Performs a motion in DIR direction at minimum speed until the SW is released (open), the ACT action is executed then a HardStop takes place
+ L6470_GOHOME_ID, //!< Brings the motor into HOME position
+ L6470_GOMARK_ID, //!< Brings the motor into MARK position
+ L6470_RESETPOS_ID, //!< Resets the ABS_POS register (set HOME position)
+ L6470_RESETDEVICE_ID, //!< Device is reset to power-up conditions
+ L6470_SOFTSTOP_ID, //!< Stops motor with a deceleration phase
+ L6470_HARDSTOP_ID, //!< Stops motor immediately
+ L6470_SOFTHIZ_ID, //!< Puts the bridges into high impedance status after a deceleration phase
+ L6470_HARDHIZ_ID, //!< Puts the bridges into high impedance status immediately
+ L6470_GETSTATUS_ID //!< Returns the STATUS register value
+} eL6470_AppCmdId_t;
+
+/**
+ * @brief The L6470 Status Register Flag identifiers.
+ */
+typedef enum {
+ HiZ_ID = 0, //!< HiZ flag identifier inside the L6470 Status Register
+ BUSY_ID, //!< BUSY flag identifier inside the L6470 Status Register
+ SW_F_ID, //!< SW_F flag identifier inside the L6470 Status Register
+ SW_EVN_ID, //!< SW_EVN flag identifier inside the L6470 Status Register
+ DIR_ID, //!< DIR flag identifier inside the L6470 Status Register
+ MOT_STATUS_ID, //!< MOT_STATUS flag identifier inside the L6470 Status Register
+ NOTPERF_CMD_ID, //!< NOTPERF_CMD flag identifier inside the L6470 Status Register
+ WRONG_CMD_ID, //!< WRONG_CMD flag identifier inside the L6470 Status Register
+ UVLO_ID, //!< UVLO flag identifier inside the L6470 Status Register
+ TH_WRN_ID, //!< TH_WRN flag identifier inside the L6470 Status Register
+ TH_SD_ID, //!< TH_SD flag identifier inside the L6470 Status Register
+ OCD_ID, //!< OCD flag identifier inside the L6470 Status Register
+ STEP_LOSS_A_ID, //!< STEP_LOSS_A flag identifier inside the L6470 Status Register
+ STEP_LOSS_B_ID, //!< STEP_LOSS_B flag identifier inside the L6470 Status Register
+ SCK_MOD_ID //!< SCK_MOD flag identifier inside the L6470 Status Register
+} eL6470_StatusRegisterFlagId_t;
+
+/**
+ * @brief The L6470 Direction identifiers.
+ */
+typedef enum {
+ L6470_DIR_REV_ID = 0, //!< Reverse direction
+ L6470_DIR_FWD_ID //!< Forward direction
+} eL6470_DirId_t;
+
+/**
+ * @brief The L6470 Action identifiers about ABS_POS register.
+ */
+typedef enum {
+ L6470_ACT_RST_ID = 0, //!< ABS_POS register is reset
+ L6470_ACT_CPY_ID //!< ABS_POS register value is copied into the MARK register
+} eL6470_ActId_t;
+
+/**
+ * @brief The L6470 Status Register Flag states.
+ */
+typedef enum {
+ ZERO_F = 0, //!< The flag is '0'
+ ONE_F = !ZERO_F //!< The flag is '1'
+} eFlagStatus_t;
+
+/**
+ * @brief The L6470 Motor Directions.
+ */
+typedef enum {
+ REVERSE_F = 0, //!< Reverse motor direction
+ FORWARD_F = !REVERSE_F //!< Forward motor direction
+} eMotorDirection_t;
+
+/**
+ * @brief The L6470 Motor Status.
+ */
+typedef enum {
+ STOPPED_F = 0, //!< Stopped
+ ACCELERATION_F = 1, //!< Acceleration
+ DECELERATION_F = 2, //!< Deceleration
+ CONSTANTSPEED_F = 3 //!< Constant speed
+} eMotorStatus_t;
+
+/**
+ * @brief The possible stepping modes for L6470.
+ */
+typedef enum
+{
+ FULL_STEP = 0x00, //!< Full-step
+ HALF_STEP = 0x01, //!< Half-step
+ MICROSTEP_1_4 = 0x02, //!< 1/4 microstep
+ MICROSTEP_1_8 = 0x03, //!< 1/8 microstep
+ MICROSTEP_1_16 = 0x04, //!< 1/16 microstep
+ MICROSTEP_1_32 = 0x05, //!< 1/32 microstep
+ MICROSTEP_1_64 = 0x06, //!< 1/64 microstep
+ MICROSTEP_1_128 = 0x07 //!< 1/128 microstep
+} eMotorStepMode_t;
+
+/**
+ * @brief The identifiers for the possible L6470 alarm conditions.
+ */
+typedef enum
+{
+ L6470_OVERCURRENT = 0x01, //!< Overcurrent
+ L6470_THERMAL_SHUTDOWN = 0x02, //!< Thermal shutdown
+ L6470_THERMAL_WARNING = 0x04, //!< Thermal warning
+ L6470_UNDERVOLTAGE = 0x08, //!< Undervoltage
+ L6470_STALL_DETECTION_A = 0x10, //!< Stall detection (Bridge A)
+ L6470_STALL_DETECTION_B = 0x20, //!< Stall detection (Bridge B)
+ L6470_SWITCH_TURN_ON_EVENT = 0x40, //!< Switch turn-on event
+ L6470_WRONG_OR_NON_PERFORMABLE_COMMAND = 0x80 //!< Wrong or non-performable command
+} eL6470_AlarmCondition_t;
+
+/**
+ * @brief The L6470 STEP_MODE Register (see L6470 DataSheet for more details).
+ */
+typedef struct {
+ uint8_t STEP_SEL: 3; //!< Step mode
+ uint8_t WRT: 1; //!< When the register is written, this bit should be set to 0.
+ uint8_t SYNC_SEL: 3; //!< Synchronization selection
+ uint8_t SYNC_EN: 1; //!< Synchronization enable
+} sL6470_StepModeRegister_t;
+
+/**
+ * @brief The L6470 ALARM_EN Register (see L6470 DataSheet for more details).
+ */
+typedef struct {
+ uint8_t OCD_EN: 1; //!< Overcurrent
+ uint8_t TH_SD_EN: 1; //!< Thermal shutdown
+ uint8_t TH_WRN_EN: 1; //!< Thermal warning
+ uint8_t UVLO_EN: 1; //!< Undervoltage
+ uint8_t STEP_LOSS_A_EN: 1; //!< Stall detection (Bridge A)
+ uint8_t STEP_LOSS_B_EN: 1; //!< Stall detection (Bridge B)
+ uint8_t SW_EVN_EN: 1; //!< Switch turn-on event
+ uint8_t WRONG_NOTPERF_CMD_EN: 1; //!< Wrong or non-performable command
+} sL6470_AlarmEnRegister_t;
+
+/**
+ * @brief The L6470 CONFIG Register (see L6470 DataSheet for more details).
+ */
+typedef struct {
+ uint8_t OSC_SEL: 3; //!< Oscillator Selection
+ uint8_t EXT_CLK: 1; //!< External Clock
+ uint8_t SW_MODE: 1; //!< Switch mode
+ uint8_t EN_VSCOMP: 1; //!< Motor supply voltage compensation
+ uint8_t RESERVED: 1; //!< RESERVED
+ uint8_t OC_SD: 1; //!< Overcurrent event
+ uint8_t POW_SR: 2; //!< Output slew rate
+ uint8_t F_PWM_DEC: 3; //!< Multiplication factor
+ uint8_t F_PWM_INT: 3; //!< Integer division factor
+} sL6470_ConfigRegister_t;
+
+/**
+ * @brief The L6470 STATUS Register (see L6470 DataSheet for more details).
+ */
+typedef struct {
+ uint8_t HiZ: 1; //!< The bridges are in high impedance state (the flag is active high)
+ uint8_t BUSY: 1; //!< BUSY pin status (the flag is active low)
+ uint8_t SW_F: 1; //!< SW input status (the flag is low for open and high for closed)
+ uint8_t SW_EVN: 1; //!< Switch turn-on event (the flag is active high)
+ uint8_t DIR: 1; //!< The current motor direction (1 as forward, 0 as reverse)
+ uint8_t MOT_STATUS: 2; //!< The current motor status (0 as stopped, 1 as acceleration, 2 as deceleration, 3 as constant speed)
+ uint8_t NOTPERF_CMD: 1; //!< The command received by SPI cannot be performed (the flag is active high)
+ uint8_t WRONG_CMD: 1; //!< The command received by SPI does not exist at all (the flag is active high)
+ uint8_t UVLO: 1; //!< Undervoltage lockout or reset events (the flag is active low)
+ uint8_t TH_WRN: 1; //!< Thermal warning event (the flag is active low)
+ uint8_t TH_SD: 1; //!< Thermal shutdown event (the flag is active low)
+ uint8_t OCD: 1; //!< Overcurrent detection event (the flag is active low)
+ uint8_t STEP_LOSS_A: 1; //!< Stall detection on bridge A (the flag is active low)
+ uint8_t STEP_LOSS_B: 1; //!< Stall detection on bridge B (the flag is active low)
+ uint8_t SCK_MOD: 1; //!< Step-clock mode (the flag is active high)
+} sL6470_StatusRegister_t;
+
+/**
+ * @brief Motor Parameter Data
+ */
+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
+} MICROSTEPPING_MOTOR_InitTypeDef;
+
+/**
+ * @brief Stepper Motor Registers
+ */
+typedef struct
+{
+ uint32_t ABS_POS; //!< CurrentPosition Register
+ uint16_t EL_POS; //!< ElectricalPosition Register
+ uint32_t MARK; //!< MarkPosition Register
+ uint32_t SPEED; //!< CurrentSpeed Register
+ uint16_t ACC; //!< Acceleration Register
+ uint16_t DEC; //!< Deceleration Register
+ uint16_t MAX_SPEED; //!< MaximumSpeed Register
+ uint16_t MIN_SPEED; //!< MinimumSpeed Register
+ uint16_t FS_SPD; //!< FullStepSpeed Register
+ uint8_t KVAL_HOLD; //!< HoldingKval Register
+ uint8_t KVAL_RUN; //!< ConstantSpeedKval Register
+ uint8_t KVAL_ACC; //!< AccelerationStartingKval Register
+ uint8_t KVAL_DEC; //!< DecelerationStartingKval Register
+ uint16_t INT_SPEED; //!< IntersectSpeed Register
+ uint8_t ST_SLP; //!< StartSlope Register
+ uint8_t FN_SLP_ACC; //!< AccelerationFinalSlope Register
+ uint8_t FN_SLP_DEC; //!< DecelerationFinalSlope Register
+ uint8_t K_THERM; //!< ThermalCompensationFactor Register
+ uint8_t ADC_OUT; //!< AdcOutput Register
+ uint8_t OCD_TH; //!< OcdThreshold Register
+ uint8_t STALL_TH; //!< StallThreshold Register
+ uint8_t STEP_MODE; //!< StepMode Register
+ uint8_t ALARM_EN; //!< AlarmEnable Register
+ uint16_t CONFIG; //!< Config Register
+ uint16_t STATUS; //!< Status Register
+} StepperMotorRegister_t;
+
+/**
+ * @brief Stepper Motor Driver Structure
+ */
+typedef struct
+{
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here the component's generic functions. *
+ * Tag this group of functions with the " Generic " C-style comment. *
+ * A component's interface has to define at least the two generic *
+ * functions provided here below within the "Example" section, as the *
+ * first and second functions of its Virtual Table. They have to be *
+ * specified exactly in the given way. *
+ * *
+ * Example: *
+ * DrvStatusTypeDef (*Init)(void *handle, INTERFACE_InitTypeDef *init); *
+ * DrvStatusTypeDef (*ReadID)(void *handle, uint8_t *id); *
+ *------------------------------------------------------------------------*/
+ /* Generic */
+ DrvStatusTypeDef (*Init)(void *handle, MICROSTEPPING_MOTOR_InitTypeDef *init);
+ DrvStatusTypeDef (*ReadID)(void *handle, uint8_t *id);
+
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here the component's specific functions. *
+ * Tag this group of functions with the " Specific " C-style comment. *
+ * Do not specify any function if not required. *
+ * *
+ * Example: *
+ * DrvStatusTypeDef (*GetValue)(void *handle, float *pfData); *
+ *------------------------------------------------------------------------*/
+ /* Specific */
+ void (*SetParam)(void *handle, eL6470_RegId_t L6470_RegId, uint32_t Value);
+ uint32_t (*GetParam)(void *handle, eL6470_RegId_t L6470_RegId);
+ void (*Run)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void (*StepClock)(void *handle, eL6470_DirId_t L6470_DirId);
+ void (*Move)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t N_Step);
+ void (*GoTo)(void *handle, uint32_t AbsPos);
+ void (*GoToDir)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
+ void (*GoUntil)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void (*ReleaseSW)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
+ void (*GoHome)(void *handle);
+ void (*GoMark)(void *handle);
+ void (*ResetPos)(void *handle);
+ void (*ResetDevice)(void *handle);
+ void (*SoftStop)(void *handle);
+ void (*HardStop)(void *handle);
+ void (*SoftHiZ)(void *handle);
+ void (*HardHiZ)(void *handle);
+ uint16_t (*GetStatus)(void *handle);
+ void (*PrepareSetParam)(void *handle, eL6470_RegId_t L6470_RegId, uint32_t Value);
+ void (*PrepareGetParam)(void *handle, eL6470_RegId_t L6470_RegId);
+ void (*PrepareRun)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void (*PrepareStepClock)(void *handle, eL6470_DirId_t L6470_DirId);
+ void (*PrepareMove)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t N_Step);
+ void (*PrepareGoTo)(void *handle, uint32_t AbsPos);
+ void (*PrepareGoToDir)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
+ void (*PrepareGoUntil)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void (*PrepareReleaseSW)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
+ void (*PrepareGoHome)(void *handle);
+ void (*PrepareGoMark)(void *handle);
+ void (*PrepareResetPos)(void *handle);
+ void (*PrepareResetDevice)(void *handle);
+ void (*PrepareSoftStop)(void *handle);
+ void (*PrepareHardStop)(void *handle);
+ void (*PrepareSoftHiZ)(void *handle);
+ void (*PrepareHardHiZ)(void *handle);
+ void (*PrepareGetStatus)(void *handle);
+ uint8_t (*CheckStatusRegisterFlag)(void *handle, uint8_t L6470_StatusRegisterFlagId);
+ uint8_t* (*PerformPreparedApplicationCommand)(void *handle);
+ uint8_t* (*GetRegisterName)(void *handle, uint8_t id);
+ int32_t (*AbsPos_2_Position)(void *handle, uint32_t AbsPos);
+ uint32_t (*Position_2_AbsPos)(void *handle, int32_t Position);
+ float (*Speed_2_Step_s)(void *handle, uint32_t Speed);
+ uint32_t (*Step_s_2_Speed)(void *handle, float Step_s);
+ float (*Acc_2_Step_s2)(void *handle, uint16_t Acc);
+ uint16_t (*Step_s2_2_Acc)(void *handle, float Step_s2);
+ float (*Dec_2_Step_s2)(void *handle, uint16_t Dec);
+ uint16_t (*Step_s2_2_Dec)(void *handle, float Step_s2);
+ float (*MaxSpeed_2_Step_s)(void *handle, uint16_t MaxSpeed);
+ uint16_t (*Step_s_2_MaxSpeed)(void *handle, float Step_s);
+ float (*MinSpeed_2_Step_s)(void *handle, uint16_t MinSpeed);
+ uint16_t (*Step_s_2_MinSpeed)(void *handle, float Step_s);
+ float (*FsSpd_2_Step_s)(void *handle, uint16_t FsSpd);
+ uint16_t (*Step_s_2_FsSpd)(void *handle, float Step_s);
+ float (*IntSpeed_2_Step_s)(void *handle, uint16_t IntSpeed);
+ uint16_t (*Step_s_2_IntSpeed)(void *handle, float Step_s);
+ float (*StSlp_2_s_Step)(void *handle, uint8_t StSlp);
+ uint8_t (*s_Step_2_StSlp)(void *handle, float s_Step);
+ float (*FnSlpAcc_2_s_Step)(void *handle, uint8_t FnSlpAcc);
+ uint8_t (*s_Step_2_FnSlpAcc)(void *handle, float s_Step);
+ float (*FnSlpDec_2_s_Step)(void *handle, uint8_t FnSlpDec);
+ uint8_t (*s_Step_2_FnSlpDec)(void *handle, float s_Step);
+ float (*OcdTh_2_mA)(void *handle, uint8_t OcdTh);
+ uint8_t (*mA_2_OcdTh)(void *handle, float mA);
+ float (*StallTh_2_mA)(void *handle, uint8_t StallTh);
+ uint8_t (*mA_2_StallTh)(void *handle, float mA);
+} MICROSTEPPING_MOTOR_DrvVTableTypeDef;
+
+/**
+ * @brief Stepper Motor Board Driver Structure
+ */
+typedef struct
+{
+ void (*SetParam)(uint8_t, uint8_t, eL6470_RegId_t, uint32_t);
+ uint32_t (*GetParam)(uint8_t, uint8_t, eL6470_RegId_t);
+ void (*Run)(uint8_t, uint8_t, eL6470_DirId_t, uint32_t);
+ void (*StepClock)(uint8_t, uint8_t, eL6470_DirId_t);
+ void (*Move)(uint8_t, uint8_t, eL6470_DirId_t, uint32_t);
+ void (*GoTo)(uint8_t, uint8_t L6470_Id, uint32_t AbsPos);
+ void (*GoToDir)(uint8_t, uint8_t, eL6470_DirId_t, uint32_t);
+ void (*GoUntil)(uint8_t, uint8_t, eL6470_ActId_t, eL6470_DirId_t, uint32_t);
+ void (*ReleaseSW)(uint8_t, uint8_t, eL6470_ActId_t, eL6470_DirId_t);
+ void (*GoHome)(uint8_t, uint8_t);
+ void (*GoMark)(uint8_t, uint8_t);
+ void (*ResetPos)(uint8_t, uint8_t);
+ void (*ResetDevice)(uint8_t, uint8_t);
+ void (*SoftStop)(uint8_t, uint8_t);
+ void (*HardStop)(uint8_t, uint8_t);
+ void (*SoftHiZ)(uint8_t, uint8_t);
+ void (*HardHiZ)(uint8_t, uint8_t);
+ uint16_t (*GetStatus)(uint8_t, uint8_t);
+ uint8_t (*CheckStatusRegisterFlag)(uint8_t, uint8_t, uint8_t);
+ uint8_t* (*PerformPreparedApplicationCommand)(uint8_t);
+} MICROSTEPPING_MOTOR_EB_DrvVTableTypeDef;
+
+/**
+ * @brief Stepper Motor Handle Structure
+ */
+typedef struct __StepperMotorDriver_HandleTypeDef
+{
+ uint8_t DaisyChainPosition;
+ void (*Config)(MICROSTEPPING_MOTOR_InitTypeDef*);
+ MICROSTEPPING_MOTOR_DrvVTableTypeDef *Command;
+} StepperMotorDriverHandle_t;
+
+/**
+ * @brief Stepper Motor Handle Structure
+ */
+typedef struct __StepperMotorBoard_HandleTypeDef
+{
+ uint8_t StackedPosition;
+ void (*Config)(MICROSTEPPING_MOTOR_InitTypeDef*);
+ MICROSTEPPING_MOTOR_EB_DrvVTableTypeDef *Command;
+ StepperMotorDriverHandle_t *StepperMotorDriverHandle[2];
+ uint8_t (*Select)(uint8_t);
+} StepperMotorBoardHandle_t;
+
+/**
+ * @}
+ */ /* StepperMotorExportedTypes */
+
+/**
+ * @}
+ */ /* MicrosteppingMotorDriver */
+
+/**
+ * @}
+ */ /* Components */
+
+/**
+ * @}
+ */ /* BSP */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MICROSTEPPINGMOTOR_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Interfaces/Component_class.h Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,75 @@
+/**
+ ******************************************************************************
+ * @file Component_class.h
+ * @author AST / EST
+ * @version V0.0.1
+ * @date 13-April-2015
+ * @brief This file contains the abstract class describing the interface of a
+ * generic component.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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 from recursive inclusion --------------------------------*/
+
+#ifndef __COMPONENT_CLASS_H
+#define __COMPONENT_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include <stdint.h>
+
+
+/* Classes ------------------------------------------------------------------*/
+
+/** An abstract class for Generic components.
+ */
+class Component
+{
+public:
+ /**
+ * @brief Initialization of the component.
+ * @param[out] ptr Pointer to device specific initalization structure.
+ * @return 0 in case of success, an error code otherwise.
+ */
+ virtual int Init(void *ptr) = 0;
+
+ /**
+ * @brief Get ID of the component.
+ * @param[out] id Pointer to where to store the ID to.
+ * @return 0 in case of success, an error code otherwise.
+ */
+ virtual int ReadID(uint8_t *id) = 0;
+};
+
+#endif /* __COMPONENT_CLASS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Interfaces/StepperMotor_class.h Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,156 @@
+/**
+ ******************************************************************************
+ * @file StepperMotor_class.h
+ * @author AST
+ * @version V1.0.0
+ * @date November 12th, 2015
+ * @brief This file contains the abstract class describing the interface of a
+ * steppermotor component.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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 from recursive inclusion --------------------------------*/
+
+#ifndef __STEPPERMOTOR_CLASS_H
+#define __STEPPERMOTOR_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include <Component_class.h>
+
+
+/* Classes ------------------------------------------------------------------*/
+
+/** An abstract class for StepperMotor components.
+ */
+class StepperMotor : public Component
+{
+public:
+ /** Rotation modes. */
+ typedef enum
+ {
+ BWD = 0, /* Backward. */
+ FWD = 1 /* Forward. */
+ } direction_t;
+
+ /**
+ * @brief Getting the status.
+ * @param None.
+ * @retval None.
+ */
+ virtual unsigned int GetStatus(void) = 0;
+
+ /**
+ * @brief Getting a parameter.
+ * @param parameter register adress.
+ * @retval a register value.
+ */
+ virtual unsigned int GetParameter(unsigned int parameter) = 0;
+
+ /* Return the current position. */
+ virtual signed int GetPosition(void) = 0;
+
+ /* Return the mark position. */
+ virtual signed int GetMark(void) = 0;
+
+ /* Return the current speed in pps. */
+ virtual unsigned int GetSpeed(void) = 0;
+
+ /* Return the maximum speed in pps. */
+ virtual unsigned int GetMaxSpeed(void) = 0;
+
+ /* Return the minimum speed in pps. */
+ virtual unsigned int GetMinSpeed(void) = 0;
+
+ /* Return the acceleration in pps^2. */
+ virtual unsigned int GetAcceleration(void) = 0;
+
+ /* Return the deceleration in pps^2. */
+ virtual unsigned int GetDeceleration(void) = 0;
+
+ /* Get the current direction of rotation. */
+ virtual direction_t GetDirection(void) = 0;
+
+ /**
+ * @brief Setting a parameter.
+ * @param parameter register adress.
+ * @param value value to be set.
+ * @retval None.
+ */
+ virtual void SetParameter(unsigned int parameter, unsigned int value) = 0;
+
+ /* Set the current position to be the home position. */
+ virtual void SetHome(void) = 0;
+
+ /* Set the current position to be the mark position. */
+ virtual void SetMark(void) = 0;
+
+ /* Set the maximum speed in pps. */
+ virtual void SetMaxSpeed(unsigned int speed) = 0;
+
+ /* Set the minimum speed in pps. */
+ virtual void SetMinSpeed(unsigned int speed) = 0;
+
+ /* Set the acceleration in pps^2. */
+ virtual void SetAcceleration(unsigned int acceleration) = 0;
+
+ /* Set the deceleration in pps^2. */
+ virtual void SetDeceleration(unsigned int deceleration) = 0;
+
+ /* Go to the specified position. */
+ virtual void GoTo(signed int position) = 0;
+
+ /* Go to the home position. */
+ virtual void GoHome(void) = 0;
+
+ /* Go to the marked position. */
+ virtual void GoMark(void) = 0;
+
+ /* Run the motor towards a specified direction. */
+ virtual void Run(direction_t direction) = 0;
+
+ /* Run the motor towards a specified direction for a specified number of steps. */
+ virtual void Move(direction_t direction, unsigned int steps) = 0;
+
+ /* Stop the motor. */
+ virtual void SoftStop(void) = 0;
+
+ /* Stop the motor and disable the power bridge. */
+ virtual void HardStop(void) = 0;
+
+ /* Wait while the motor is active. */
+ virtual void WaitWhileActive(void) = 0;
+};
+
+#endif /* __STEPPERMOTOR_CLASS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6470/l6470.h Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,260 @@
+/**
+ ******************************************************************************
+ * @file L6470.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 "microstepping_motor.h"
+
+/**
+ * @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 */
+
+/**
+ * @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
+
+
+/**
+ * @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_DrvDataTypeDef; *
+ * ---------------------------------------------------------------------------*/
+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_DrvDataTypeDef;
+
+
+/* Functions -----------------------------------------------------------------*/
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @addtogroup L6470
+ * @{
+ */
+
+/** @defgroup L6470_IO_Functions L6470_IO_Functions
+ * @{
+ */
+/* ACTION --------------------------------------------------------------------*
+ * Declare here extern I/O functions you need and implemented them in a glue *
+ * logic file on the target environment, for example within the expansion *
+ * board "*.c" file. E.g.: *
+ * extern DrvStatusTypeDef COMPONENT_IO_Read (handle, buf, regadd, bytes); *
+ * extern DrvStatusTypeDef COMPONENT_IO_Write(handle, buf, regadd, bytes); *
+ *----------------------------------------------------------------------------*/
+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);
+
+/**
+ * @}
+ */ /* End of L6470_Exported_Variables */
+
+/**
+ * @}
+ */ /* End of L6470 */
+
+/**
+ * @}
+ */ /* End of Components */
+
+/**
+ * @}
+ */ /* End of BSP */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __L6470_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6470/l6470_class.cpp Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,1527 @@
+/**
+ ******************************************************************************
+ * @file L6470.c
+ * @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_class.h"
+#include "l6470.h"
+
+
+/* Definitions ---------------------------------------------------------------*/
+
+/**
+ * @defgroup L6470_Private_Macros
+ * @brief L6470 Private Macros.
+ * @{
+ */
+//#define _DELAY(TDISCS) for(delay_cnt=0; delay_cnt<20; delay_cnt++) __NOP() //!<Simply deselect time delay for SPI nCS
+/* End of L6470_Private_Macros */
+
+
+/* Methods -------------------------------------------------------------------*/
+
+/**
+ * @defgroup L6470_Conversion_Functions
+ * @brief The following functions act just on one driver inside the L6470
+ * daisy chain. The command is immediately sent.
+ * @{
+ */
+
+/* End of L6470_Conversion_Functions */
+
+/**
+ * @defgroup L6470_AppCMDs
+ * @brief The following functions act just on one driver inside the L6470
+ * daisy chain. The command is immediately sent.
+ * @{
+ */
+
+/* End of L6470_AppCMDs */
+
+/**
+ * @defgroup L6470_AppCMDs_ToBePrepared
+ * @brief The following functions act just on one driver inside the L6470 daisy
+ * chain. The command is prepared and not sent. To send the application
+ * commands already prepared for the addressed L6470 drivers you have to
+ * use @ref L6470_PerformPreparedApplicationCommand.
+ * @{
+ */
+
+/* End of L6470_AppCMDs_ToBePrepared */
+
+/**
+ * @defgroup L6470_Private_Functions
+ * @brief L6470 Private Functions.
+ * @{
+ */
+
+/* End of L6470_Private_Functions */
+
+
+/**
+ * @addtogroup BSP
+ * @{
+ */
+
+/**
+ * @addtogroup Components
+ * @{
+ */
+
+/**
+ * @addtogroup L6470
+ * @{
+ */
+
+/**
+ * @defgroup L6470_Private_Constants
+ * @brief L6470 Private Constants.
+ * @{
+ */
+
+/* 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
+ * @{
+ */
+
+/**
+ * @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 StepperMotorDriverHandle_t* The pointer to the stepper motor driver handle structure.
+ * @param MotorParameterData_t* The pointer to the related parameter data structure.
+ */
+DrvStatusTypeDef L6470::L6470_Config(MICROSTEPPING_MOTOR_InitTypeDef *MotorParameterData)
+{
+ /* Disable the L6470. */
+ L6470_DISABLE();
+
+ /* Enable the L6470. */
+ L6470_ENABLE();
+
+ /* Reset devices. */
+ ResetDevice();
+
+ /* Reset Status Register flags. */
+ GetStatus();
+
+ /* Prepare the 'Register' field of StepperMotorDriverHandle */
+ 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.STEP_MODE = MotorParameterData->step_sel;
+ StepperMotorRegister.ALARM_EN = MotorParameterData->alarmen;
+ StepperMotorRegister.CONFIG = MotorParameterData->config;
+
+ /* 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_STEP_MODE_ID, StepperMotorRegister.STEP_MODE);
+ L6470_SetParam(L6470_ALARM_EN_ID, StepperMotorRegister.ALARM_EN);
+ L6470_SetParam(L6470_CONFIG_ID, StepperMotorRegister.CONFIG);
+
+ 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_class.h Fri Nov 20 18:07:45 2015 +0000
@@ -0,0 +1,787 @@
+/**
+ ******************************************************************************
+ * @file L6470.c
+ * @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.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.h"
+/* ACTION 3 ------------------------------------------------------------------*
+ * Include here interface specific header files. *
+ * *
+ * Example: *
+ * #include "../Interfaces/Humidity_class.h" *
+ * #include "../Interfaces/Temperature_class.h" *
+ *----------------------------------------------------------------------------*/
+#include "../Interfaces/StepperMotor_class.h"
+
+
+/* Classes -------------------------------------------------------------------*/
+
+/** Class representing a L6470 component.
+ */
+class L6470 : public StepperMotor
+{
+public:
+
+ /*** Constructor and Destructor Methods ***/
+
+ /**
+ * @brief Constructor.
+ * @param flag_irq pin name of the FLAG 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 standby_reset, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), standby_reset(standby_reset), ssel(ssel), dev_spi(spi)
+ {
+ /* ACTION 4 ----------------------------------------------------------*
+ * Initialize here the component's member variables, one variable per *
+ * line. *
+ * *
+ * Example: *
+ * T0_out = 0; *
+ * T1_out = 0; *
+ * T0_degC = 0; *
+ * T1_degC = 0; *
+ *--------------------------------------------------------------------*/
+ L6470_Register = &_L6470_Register[0];
+ L6470_ApplicationCommand = &_L6470_ApplicationCommand[0];
+ L6470_Direction = &_L6470_Direction[0];
+ L6470_ACT = &_L6470_ACT[0];
+ pL6470_StatusRegister = &L6470_StatusRegister;
+ 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 GetValue(float *pData) //(1) *
+ * { *
+ * return COMPONENT_GetValue(float *pfData); *
+ * } *
+ * *
+ * virtual int EnableFeature(void) //(2) *
+ * { *
+ * return COMPONENT_EnableFeature(); *
+ * } *
+ *------------------------------------------------------------------------*/
+ virtual int Init(void *init)
+ {
+ return (int) L6470_Config((MICROSTEPPING_MOTOR_InitTypeDef *) init);
+ }
+
+ virtual int ReadID(uint8_t *id)
+ {
+ return (int) 0;
+ }
+
+ virtual unsigned int GetStatus(void)
+ {
+ return (unsigned int) L6470_GetStatus();
+ }
+
+ virtual unsigned int GetParameter(unsigned int parameter)
+ {
+ return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter);
+ }
+
+ virtual signed int GetPosition(void)
+ {
+ return (signed int) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID);
+ }
+
+ virtual signed int GetMark(void)
+ {
+ return (signed int) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID);
+ }
+
+ virtual unsigned int GetSpeed(void)
+ {
+ return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID);
+ }
+
+ virtual unsigned int GetMaxSpeed(void)
+ {
+ return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID);
+ }
+
+ virtual unsigned int GetMinSpeed(void)
+ {
+ return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID);
+ }
+
+ virtual unsigned int GetAcceleration(void)
+ {
+ return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID);
+ }
+
+ virtual unsigned int GetDeceleration(void)
+ {
+ return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID);
+ }
+
+ virtual direction_t GetDirection(void)
+ {
+ return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
+ }
+
+ virtual void SetParameter(unsigned int parameter, unsigned int value)
+ {
+ L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value);
+ }
+
+ virtual void SetHome(void)
+ {
+ L6470_ResetPos();
+ //L6470_SetParam((eL6470_RegId_t) L6470_ABS_POS_ID, (uint32_t) 0);
+ }
+
+ virtual void SetMark(void)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
+ //L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) 0);
+ }
+
+ virtual void SetMaxSpeed(unsigned int speed)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) speed);
+ }
+
+ virtual void SetMinSpeed(unsigned int speed)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) speed);
+ }
+
+ virtual void SetAcceleration(unsigned int acceleration)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) acceleration);
+ }
+
+ virtual void SetDeceleration(unsigned int deceleration)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) deceleration);
+ }
+
+ virtual void GoTo(signed int position)
+ {
+ L6470_GoTo((uint32_t) position);
+ }
+
+ virtual void GoTo(signed int position, direction_t direction)
+ {
+ L6470_GoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (signed int) position);
+ }
+
+ virtual void GoHome(void)
+ {
+ L6470_GoHome();
+ }
+
+ virtual void GoMark(void)
+ {
+ L6470_GoMark();
+ }
+
+ virtual void GoUntil(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed)
+ {
+ L6470_GoUntil((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) speed);
+ }
+
+ 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));
+ }
+
+ 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) speed);
+ }
+
+ 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);
+ }
+
+ virtual void SoftStop(void)
+ {
+ L6470_SoftStop();
+ }
+
+ virtual void HardStop(void)
+ {
+ L6470_HardStop();
+ }
+
+ virtual void WaitWhileActive(void)
+ {
+ while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0);
+ }
+
+ virtual void SoftHiZ(void)
+ {
+ L6470_SoftHiZ();
+ }
+
+ virtual void HardHiZ(void)
+ {
+ L6470_HardHiZ();
+ }
+
+ virtual void StepClock(direction_t direction)
+ {
+ L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ }
+
+ virtual void ReleaseSW(eL6470_ActId_t L6470_ActId, direction_t direction)
+ {
+ L6470_ReleaseSW((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ }
+
+ virtual void ResetDevice(void)
+ {
+ L6470_ResetDevice();
+ }
+
+ virtual void PrepareGetStatus(void)
+ {
+ L6470_PrepareGetStatus();
+ }
+
+ virtual void PrepareGetParameter(unsigned int parameter)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) parameter);
+ }
+
+ virtual void PrepareGetPosition(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID);
+ }
+
+ virtual void PrepareGetMark(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID);
+ }
+
+ virtual void PrepareGetSpeed(void)
+ {
+ L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID);
+ }
+
+ virtual void PrepareGetMaxSpeed(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID);
+ }
+
+ virtual void PrepareGetMinSpeed(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID);
+ }
+
+ virtual void PrepareGetAcceleration(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID);
+ }
+
+ virtual void PrepareGetDeceleration(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID);
+ }
+
+ virtual direction_t PrepareGetDirection(void)
+ {
+ return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
+ }
+
+ virtual void PrepareSetParameter(unsigned int parameter, unsigned int value)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value);
+ }
+
+ virtual void PrepareSetHome(void)
+ {
+ L6470_PrepareResetPos();
+ //L6470_SetParam((eL6470_RegId_t) L6470_ABS_POS_ID, (uint32_t) 0);
+ }
+
+ virtual void PrepareSetMark(void)
+ {
+ uint32_t mark = L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID);
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, mark);
+ }
+
+ virtual void PrepareSetMaxSpeed(unsigned int speed)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) speed);
+ }
+
+ virtual void PrepareSetMinSpeed(unsigned int speed)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) speed);
+ }
+
+ virtual void PrepareSetAcceleration(unsigned int acceleration)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) acceleration);
+ }
+
+ virtual void PrepareSetDeceleration(unsigned int deceleration)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) deceleration);
+ }
+
+ virtual void PrepareGoTo(signed int position)
+ {
+ L6470_PrepareGoTo((uint32_t) position);
+ }
+
+ virtual void PrepareGoTo(signed int position, direction_t direction)
+ {
+ L6470_PrepareGoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (signed int) position);
+ }
+
+ virtual void PrepareGoHome(void)
+ {
+ L6470_PrepareGoHome();
+ }
+
+ virtual void PrepareGoMark(void)
+ {
+ L6470_PrepareGoMark();
+ }
+
+ virtual void PrepareGoUntil(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) speed);
+ }
+
+ virtual void PrepareRun(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));
+ }
+
+ virtual void PrepareRun(direction_t direction, unsigned int speed)
+ {
+ L6470_PrepareRun((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) speed);
+ }
+
+ virtual void PrepareMove(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);
+ }
+
+ virtual void PrepareSoftStop(void)
+ {
+ L6470_PrepareSoftStop();
+ }
+
+ virtual void PrepareHardStop(void)
+ {
+ L6470_PrepareHardStop();
+ }
+
+ virtual void PrepareSoftHiZ(void)
+ {
+ L6470_PrepareSoftHiZ();
+ }
+
+ virtual void PrepareHardHiZ(void)
+ {
+ L6470_PrepareHardHiZ();
+ }
+
+ virtual void PrepareStepClock(direction_t direction)
+ {
+ L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ }
+
+ virtual void PrepareReleaseSW(eL6470_ActId_t L6470_ActId, direction_t direction)
+ {
+ L6470_ReleaseSW((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ }
+
+ virtual void PrepareResetDevice(void)
+ {
+ L6470_ResetDevice();
+ }
+
+ virtual uint8_t* PerformAction(void)
+ {
+ return (uint8_t*) L6470_PerformPreparedApplicationCommand();
+ }
+
+
+ /*** 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 AttachFeatureIRQ(void (*fptr) (void)) *
+ * { *
+ * feature_irq.rise(fptr); *
+ * } *
+ * *
+ * void EnableFeatureIRQ(void) *
+ * { *
+ * feature_irq.enable_irq(); *
+ * } *
+ * *
+ * void DisableFeatureIRQ(void) *
+ * { *
+ * feature_irq.disable_irq(); *
+ * } *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief Attaching a FLAG interrupt handler.
+ * @param fptr an interrupt handler.
+ * @retval None.
+ */
+ void AttachFlagIRQ(void (*fptr)(void))
+ {
+ flag_irq.rise(fptr);
+ }
+
+ /**
+ * @brief Enabling FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void EnableFlagIRQ(void)
+ {
+ flag_irq.enable_irq();
+ }
+
+ /**
+ * @brief Disabling FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void DisableFlagIRQ(void)
+ {
+ flag_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: *
+ * DrvStatusTypeDef COMPONENT_GetValue(float* pfData); //(1) *
+ * DrvStatusTypeDef COMPONENT_EnableFeature(void); //(2) *
+ * DrvStatusTypeDef COMPONENT_ComputeAverage(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);
+ DrvStatusTypeDef L6470_Config(MICROSTEPPING_MOTOR_InitTypeDef *MotorParameterData);
+ 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);
+
+
+ /*** 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.
+ */
+ DrvStatusTypeDef 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.
+ */
+ DrvStatusTypeDef 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.
+ */
+ DrvStatusTypeDef 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)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
+ standby_reset = 1;
+ }
+
+ /*
+ * Puts the device in reset mode.
+ */
+ void L6470_DISABLE(void)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
+ 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)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
+ ReadWrite(pRxData, pTxData, Size);
+ }
+
+
+ /*** Component's Instance Variables ***/
+
+ /* Identity */
+ uint8_t who_am_i;
+
+ /* ACTION 9 --------------------------------------------------------------*
+ * There should be only a unique identifier for each component, which *
+ * should be the "who_am_i" parameter, hence this parameter is optional. *
+ *------------------------------------------------------------------------*/
+ /* Type. */
+ uint8_t type;
+
+ /* Flag Interrupt. */
+ InterruptIn flag_irq;
+
+ /* Standby/reset pin. */
+ DigitalOut standby_reset;
+
+ /* Configuration. */
+ DigitalOut ssel;
+
+ /* IO Device. */
+ DevSPI &dev_spi;
+
+ /* Interrupts. */
+ /* ACTION 10 -------------------------------------------------------------*
+ * Put here interrupt related objects, if needed. *
+ * Note that interrupt handling is platform dependent, see *
+ * "Interrupt Related Methods" above. *
+ * *
+ * Example: *
+ * + mbed: *
+ * InterruptIn feature_int; *
+ *------------------------------------------------------------------------*/
+
+ /* Data. */
+ /* ACTION 11 -------------------------------------------------------------*
+ * Declare here the component's data, one variable per line. *
+ * *
+ * Example: *
+ * int T0_out; *
+ * int T1_out; *
+ * float T0_degC; *
+ * float T1_degC; *
+ *------------------------------------------------------------------------*/
+ 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;
+
+ /* 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/X_NUCLEO_COMMON.lib Fri Nov 20 18:07:45 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#da29b5403ca1

X-NUCLEO-IHM02A1 Two Axis Stepper Motor Driver