motor board library

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   selfbalansingcar

Fork of X_NUCLEO_IHM02A1 by ST

Revision:
9:d70452d7a1e1
Parent:
3:e3f6f4474d98
Child:
10:aa68441705b2
--- a/BSP/x_nucleo_ihm02a1_class.cpp	Thu Dec 10 15:42:20 2015 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.cpp	Fri Dec 11 17:23:31 2015 +0000
@@ -57,74 +57,20 @@
 /* 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, 992.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, 992.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, 992.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, 992.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, 992.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, 992.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, 992.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, 992.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 init_0        pointer to the initialization structure of the first motor.
+ * @param init_1        pointer to the initialization structure of the second motor.
  * @param flag_irq      pin name of the FLAG pin of the component.
  * @param busy_irq      pin name of the BUSY pin of the component.
  * @param standby_reset pin name of the STBY\RST pin of the component.
  * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
  * @param spi           SPI device to be used for communication.
  */
-X_NUCLEO_IHM02A1::X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi) : dev_spi(spi)
+X_NUCLEO_IHM02A1::X_NUCLEO_IHM02A1(MICROSTEPPING_MOTOR_InitTypeDef *init_0, MICROSTEPPING_MOTOR_InitTypeDef *init_1, PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi) : dev_spi(spi)
 {
     /* SPI communication. */
     if (dev_spi == NULL)
@@ -143,12 +89,16 @@
     components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
 
     /* Initializing the components. */
+    init_components[0] = init_0;
+    init_components[1] = init_1;
     if (!Init())
         error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
 }
 
 /**
  * @brief Constructor.
+ * @param init_0        pointer to the initialization structure of the first motor.
+ * @param init_1        pointer to the initialization structure of the second motor.
  * @param flag_irq      pin name of the FLAG pin of the component.
  * @param busy_irq      pin name of the BUSY pin of the component.
  * @param standby_reset pin name of the STBY\RST pin of the component.
@@ -157,7 +107,7 @@
  * @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.
  */
-X_NUCLEO_IHM02A1::X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk)
+X_NUCLEO_IHM02A1::X_NUCLEO_IHM02A1(MICROSTEPPING_MOTOR_InitTypeDef *init_0, MICROSTEPPING_MOTOR_InitTypeDef *init_1, PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk)
 {
     /* SPI communication. */
     dev_spi = new DevSPI(mosi, miso, sclk);
@@ -175,6 +125,8 @@
     components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
 
     /* Initializing the components. */
+    init_components[0] = init_0;
+    init_components[1] = init_1;
     if (!Init())
         error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
 }
@@ -231,7 +183,7 @@
 bool X_NUCLEO_IHM02A1::Init_L6470_0(void)
 {
     /* Initialization. */
-    if (l6470_0->Init((void *) &MotorParameterInitData[X_NUCLEO_IHM02A1_Id][0]) != COMPONENT_OK)
+    if (l6470_0->Init((void *) init_components[0]) != COMPONENT_OK)
         return false;
 
     return true;
@@ -244,7 +196,7 @@
 bool X_NUCLEO_IHM02A1::Init_L6470_1(void)
 {
     /* Initialization. */
-    if (l6470_1->Init((void *) &MotorParameterInitData[X_NUCLEO_IHM02A1_Id][1]) != COMPONENT_OK)
+    if (l6470_1->Init((void *) init_components[0]) != COMPONENT_OK)
         return false;
 
     return true;