motor board library

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   selfbalansingcar

Fork of X_NUCLEO_IHM02A1 by ST

Files at this revision

API Documentation at this revision

Comitter:
Davidroid
Date:
Mon Jan 04 16:10:54 2016 +0000
Parent:
9:d70452d7a1e1
Child:
11:1aca63b2f034
Commit message:
+ Added check on expansion board's stackability.

Changed in this revision

BSP/x_nucleo_ihm02a1_class.cpp Show annotated file Show diff for this revision Revisions of this file
BSP/x_nucleo_ihm02a1_class.h Show annotated file Show diff for this revision Revisions of this file
--- a/BSP/x_nucleo_ihm02a1_class.cpp	Fri Dec 11 17:23:31 2015 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.cpp	Mon Jan 04 16:10:54 2016 +0000
@@ -52,9 +52,9 @@
 #include "x_nucleo_ihm02a1_class.h"
 
 
-/* Static variables ----------------------------------------------------------*/
+/* Variables -----------------------------------------------------------------*/
 
-/* Number of instantiated expansion boards. */
+/* Number of expansion boards. */
 uint8_t X_NUCLEO_IHM02A1::number_of_boards = 0;
 
 
@@ -72,6 +72,11 @@
  */
 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)
 {
+    /* Checking stackability. */
+    if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX))
+        error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
+    X_NUCLEO_IHM02A1_Id = number_of_boards++;
+
     /* SPI communication. */
     if (dev_spi == NULL)
         dev_spi = new DevSPI(X_NUCLEO_IHM02A1_PIN_SPI_MOSI, X_NUCLEO_IHM02A1_PIN_SPI_MISO, X_NUCLEO_IHM02A1_PIN_SPI_SCLK);
@@ -84,7 +89,6 @@
      *   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++;
     components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
     components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
 
@@ -92,7 +96,7 @@
     init_components[0] = init_0;
     init_components[1] = init_1;
     if (!Init())
-        error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
+        error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
 }
 
 /**
@@ -109,6 +113,11 @@
  */
 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)
 {
+    /* Checking stackability. */
+    if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX))
+        error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
+    X_NUCLEO_IHM02A1_Id = number_of_boards++;
+
     /* SPI communication. */
     dev_spi = new DevSPI(mosi, miso, sclk);
 
@@ -120,7 +129,6 @@
      *   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++;
     components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
     components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
 
@@ -128,7 +136,7 @@
     init_components[0] = init_0;
     init_components[1] = init_1;
     if (!Init())
-        error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
+        error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
 }
 
 /**
--- a/BSP/x_nucleo_ihm02a1_class.h	Fri Dec 11 17:23:31 2015 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.h	Mon Jan 04 16:10:54 2016 +0000
@@ -203,13 +203,15 @@
     /* Results of prepared actions. */
     uint32_t results[L6470DAISYCHAINSIZE];
 
-    /* Data. */
-    /* ACTION 11 -------------------------------------------------------------*
-     * Declare here the component's data, one variable per line.              *
+    /* ACTION 6 --------------------------------------------------------------*
+     * Declare here the component's static and non-static data, one variable  *
+     * per line.                                                              *
      *                                                                        *
      * Example:                                                               *
-     *   uint8_t ExpansionBoard_Id;                                           *
+     *   int instance_id;                                                     *
+     *   static int number_of_instances;                                      *
      *------------------------------------------------------------------------*/
+    /* Data. */
     uint8_t X_NUCLEO_IHM02A1_Id;
 
     /* Static data. */