hi

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_IHM02A1 by ST

Files at this revision

API Documentation at this revision

Comitter:
Davidroid
Date:
Wed Nov 25 17:15:37 2015 +0000
Parent:
2:3ed992ffeada
Child:
4:381d76f5b0b4
Commit message:
+ Expansion Board class updated to be non-singleton.; + Expansion Board class updated with information on SSEL pins needed when stacking more boards.

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	Wed Nov 25 14:39:33 2015 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.cpp	Wed Nov 25 17:15:37 2015 +0000
@@ -54,9 +54,6 @@
 
 /* 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;
 
@@ -129,6 +126,10 @@
  */
 X_NUCLEO_IHM02A1::X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi) : dev_spi(spi)
 {
+    /* 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);
+
     /* Instantiating the components. */
     /* ACTION 3 --------------------------------------------------------------*
      * Instantiate here the expansion board's components.                     *
@@ -140,38 +141,14 @@
     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);
+
+    /* Initializing the components. */
+    if (!Init())
+        error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
 }
 
 /**
- * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
- * @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.
- * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
- */
-X_NUCLEO_IHM02A1 *X_NUCLEO_IHM02A1::Instance(PinName flag_irq, PinName busy_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, busy_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.
+ * @brief Constructor.
  * @param flag_irq      pin name of the FLAG pin of the component.
  * @param busy_irq      pin name of the BUSY pin of the component.
  * @param standby_reset pin name of the STBY\RST pin of the component.
@@ -179,24 +156,27 @@
  * @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 busy_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk)
+X_NUCLEO_IHM02A1::X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk)
 {
-    if (_instance == NULL)
-    {
-        /* SPI communication. */
-        DevSPI *spi = new DevSPI(mosi, miso, sclk);
+    /* SPI communication. */
+    dev_spi = new DevSPI(mosi, miso, sclk);
 
-        /* Instantiating the board. */
-        _instance = new X_NUCLEO_IHM02A1(flag_irq, busy_irq, standby_reset, ssel, 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++;
+    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);
 
-        /* Initializing the components. */
-        if (!_instance->Init())
-            error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
-    }
-
-    return _instance;
+    /* Initializing the components. */
+    if (!Init())
+        error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\n");
 }
 
 /**
--- a/BSP/x_nucleo_ihm02a1_class.h	Wed Nov 25 14:39:33 2015 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.h	Wed Nov 25 17:15:37 2015 +0000
@@ -74,21 +74,20 @@
 {
 public:
 
-    /*** Instance, Initialization and Destructor Methods ***/
+    /*** Constructor, Destructor, and Initialization Methods ***/
 
     /**
-     * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
+     * @brief Constructor.
      * @param flag_irq      pin name of the FLAG pin of the component.
      * @param busy_irq      pin name of the BUSY pin of the component.
      * @param standby_reset pin name of the STBY\RST pin of the component.
      * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
      * @param spi           SPI device to be used for communication.
-     * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
      */
-    static X_NUCLEO_IHM02A1 *Instance(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi = NULL);
+    X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi);
 
     /**
-     * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
+     * @brief Constructor.
      * @param flag_irq      pin name of the FLAG pin of the component.
      * @param busy_irq      pin name of the BUSY pin of the component.
      * @param standby_reset pin name of the STBY\RST pin of the component.
@@ -96,9 +95,13 @@
      * @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 busy_irq, PinName standby_reset, PinName ssel, PinName miso, PinName mosi, PinName sclk);
+    X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk);
+
+    /**
+     * @brief Destructor.
+     */
+    ~X_NUCLEO_IHM02A1(void) {}
 
     /**
      * @brief Initializing the X_NUCLEO_IHM02A1 board.
@@ -106,10 +109,8 @@
      */
     bool Init(void);
 
-    /**
-     * @brief Destructor.
-     */
-    ~X_NUCLEO_IHM02A1(void) {}
+
+    /*** Other Public Expansion Board Related Methods ***/
 
     /**
      * @brief  Getting the array of components.
@@ -173,19 +174,6 @@
 
 protected:
 
-    /*** Protected Constructor Method ***/
-
-    /**
-     * @brief Constructor.
-     * @param flag_irq      pin name of the FLAG pin of the component.
-     * @param busy_irq      pin name of the BUSY pin of the component.
-     * @param standby_reset pin name of the STBY\RST pin of the component.
-     * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
-     * @param spi           SPI device to be used for communication.
-     */
-    X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi);
-
-
     /*** Protected Expansion Board Related Initialization Methods ***/
 
     /* ACTION 5 --------------------------------------------------------------*
@@ -202,9 +190,6 @@
 
     /*** Component's Instance Variables ***/
 
-    /* Singleton instance of X_NUCLEO_IHM02A1 class. */
-    static X_NUCLEO_IHM02A1 *_instance;
-
     /* IO Device. */
     DevSPI *dev_spi;