Fabian Scherrer / X_NUCLEO_IHM02A1

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   SpleisserProgramm SpleisserProgramm_v2 SpleisserProgramm_v5 SpleisserProgramm_V7 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XNucleoIHM02A1.cpp Source File

XNucleoIHM02A1.cpp

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    XNucleoIHM02A1.cpp
00004  * @author  AST / Software Platforms and Cloud
00005  * @version V1.0
00006  * @date    November 3rd, 2015
00007  * @brief   Implementation file for the X_NUCLEO_IHM02A1 expansion board.
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *      without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036  */
00037 
00038 
00039 /* Generated with STM32CubeTOO -----------------------------------------------*/
00040 
00041 
00042 /* Includes ------------------------------------------------------------------*/
00043 
00044 /* ACTION 1 ------------------------------------------------------------------*
00045  * Include here platform specific header files.                               *
00046  *----------------------------------------------------------------------------*/
00047 #include "mbed.h"
00048 #include "DevSPI.h"
00049 /* ACTION 2 ------------------------------------------------------------------*
00050  * Include here expansion board specific header files.                        *
00051  *----------------------------------------------------------------------------*/
00052 #include "XNucleoIHM02A1.h"
00053 
00054 
00055 /* Variables -----------------------------------------------------------------*/
00056 
00057 /* Number of expansion boards. */
00058 uint8_t XNucleoIHM02A1::number_of_boards = 0;
00059 ////fabian///----
00060 uint8_t XNucleoIHM02A12::number_of_boards1 = 0;
00061 
00062 /* Methods -------------------------------------------------------------------*/
00063 
00064 /**
00065  * @brief Constructor.
00066  * @param init_0        pointer to the initialization structure of the first motor.
00067  * @param init_1        pointer to the initialization structure of the second motor.
00068  * @param flag_irq      pin name of the FLAG pin of the component.
00069  * @param busy_irq      pin name of the BUSY pin of the component.
00070  * @param standby_reset pin name of the STBY\RST pin of the component.
00071  * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
00072  * @param spi           SPI device to be used for communication.
00073  */
00074 XNucleoIHM02A1::XNucleoIHM02A1(L6470_init_t *init_0, L6470_init_t *init_1, PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi) : dev_spi(spi)
00075 {
00076     /* Checking stackability. */
00077     if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX)) {
00078         error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
00079     }
00080     instance_id = number_of_boards++;
00081    
00082 
00083     /* SPI communication. */
00084     if (dev_spi == NULL) {
00085         dev_spi = new DevSPI(X_NUCLEO_IHM02A1_PIN_SPI_MOSI, X_NUCLEO_IHM02A1_PIN_SPI_MISO, X_NUCLEO_IHM02A1_PIN_SPI_SCLK);
00086     }
00087 
00088      
00089 
00090     /* Instantiating the components. */
00091     /* ACTION 3 --------------------------------------------------------------*
00092      * Instantiate here the expansion board's components.                     *
00093      *                                                                        *
00094      * Example:                                                               *
00095      *   component_1 = new COMPONENT_1(ssel, *dev_spi);                       *
00096      *   component_2 = new COMPONENT_2(ssel, *dev_spi);                       *
00097      *------------------------------------------------------------------------*/
00098     components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00099     components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00100 
00101     /* Initializing the components. */
00102     init_components[0] = init_0;
00103     init_components[1] = init_1;
00104     if (!init()) {
00105         error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
00106     }
00107 }
00108 
00109 /**
00110  * @brief Constructor.
00111  * @param init_0        pointer to the initialization structure of the first motor.
00112  * @param init_1        pointer to the initialization structure of the second motor.
00113  * @param flag_irq      pin name of the FLAG pin of the component.
00114  * @param busy_irq      pin name of the BUSY pin of the component.
00115  * @param standby_reset pin name of the STBY\RST pin of the component.
00116  * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
00117  * @param mosi          pin name of the MOSI pin of the SPI device to be used for communication.
00118  * @param miso          pin name of the MISO pin of the SPI device to be used for communication.
00119  * @param sclk          pin name of the SCLK pin of the SPI device to be used for communication.
00120  */
00121 XNucleoIHM02A1::XNucleoIHM02A1(L6470_init_t *init_0, L6470_init_t *init_1, PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk)
00122 {
00123     /* Checking stackability. */
00124     if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX)) {
00125         error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
00126     }
00127     instance_id = number_of_boards++;
00128     
00129     printf("--> so viele boards %d.\r\n",number_of_boards);
00130     
00131     /* SPI communication. */
00132     dev_spi = new DevSPI(mosi, miso, sclk);
00133 
00134     /* Instantiating the components. */
00135     /* ACTION 3 --------------------------------------------------------------*
00136      * Instantiate here the expansion board's components.                     *
00137      *                                                                        *
00138      * Example:                                                               *
00139      *   component_1 = new COMPONENT_1(ssel, *dev_spi);                       *
00140      *   component_2 = new COMPONENT_2(ssel, *dev_spi);                       *
00141      *------------------------------------------------------------------------*/
00142     components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00143     components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00144 
00145     /* Initializing the components. */
00146     init_components[0] = init_0;
00147     init_components[1] = init_1;
00148     if (!init()) {
00149         error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
00150     }
00151 }
00152 
00153 /**
00154  * @brief Initializing the X_NUCLEO_IHM02A1 board.
00155  * @retval true if initialization is successful, false otherwise.
00156  */
00157 bool XNucleoIHM02A1::init(void)
00158 {
00159     /* Initializing the components. */
00160     /* ACTION 4 --------------------------------------------------------------*
00161      * Initialize here the expansion board's components.                      *
00162      *                                                                        *
00163      * Example:                                                               *
00164      *   return (init_COMPONENT_1() && init_COMPONENT_2());                   *
00165      *------------------------------------------------------------------------*/
00166     return (init_L6470_0() && init_L6470_1());
00167 }
00168 
00169 /* ACTION 5 ------------------------------------------------------------------*
00170  * Implement here an initialization method for each expansion board's         *
00171  * component.                                                                 *
00172  *                                                                            *
00173  * Example:                                                                   *
00174  *   bool ExpansionBoard::init_COMPONENT_1(void)                              *
00175  *   {                                                                        *
00176  *     // Verifying identity.                                                 *
00177  *     uint8_t id = 0;                                                        *
00178  *     int ret = component_1->read_id(&id);                                   *
00179  *     if ((ret != COMPONENT_OK) || (id != I_AM_COMPONENT_1))                 *
00180  *     {                                                                      *
00181  *       delete component_1;                                                  *
00182  *       component_1 = NULL;                                                  *
00183  *       return true;                                                         *
00184  *     }                                                                      *
00185  *                                                                            *
00186  *     // Configuration.                                                      *
00187  *     COMPONENT_init_t init;                                                 *
00188  *     init.property_1 = COMPONENT_1_PROPERY_1_INIT;                          *
00189  *     init.property_N = COMPONENT_1_PROPERY_N_INIT;                          *
00190  *                                                                            *
00191  *     // Initialization.                                                     *
00192  *     if (component_1->init(&init) != COMPONENT_OK)                          *
00193  *       return false;                                                        *
00194  *                                                                            *
00195  *     return true;                                                           *
00196  *   }                                                                        *
00197  *----------------------------------------------------------------------------*/
00198 /**
00199  * @brief  Initialize the L6470 component.
00200  * @retval true if initialization is successful, false otherwise.
00201  */
00202 bool XNucleoIHM02A1::init_L6470_0(void)
00203 {
00204     /* Initialization. */
00205     if (l6470_0->init((void *) init_components[0]) != COMPONENT_OK) {
00206         return false;
00207     }
00208 
00209     return true;
00210 }
00211 
00212 /**
00213  * @brief  Initialize the L6470 component.
00214  * @retval true if initialization is successful, false otherwise.
00215  */
00216 bool XNucleoIHM02A1::init_L6470_1(void)
00217 {
00218     /* Initialization. */
00219     if (l6470_1->init((void *) init_components[1]) != COMPONENT_OK) {
00220         return false;
00221     }
00222 
00223     return true;
00224 }
00225 
00226 /////////////////////////////////////////////////////////////////////FABIAN
00227 
00228 XNucleoIHM02A12::XNucleoIHM02A12(L6470_init_t *init_0, L6470_init_t *init_1, PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi) : dev_spi(spi)
00229 {
00230     /* Checking stackability. */
00231     if (!(number_of_boards1 < EXPBRD_MOUNTED_NR_MAX)) {
00232         error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
00233     }
00234     instance_id = number_of_boards1++;
00235    
00236 
00237     /* SPI communication. */
00238     if (dev_spi == NULL) {
00239         dev_spi = new DevSPI(X_NUCLEO_IHM02A1_PIN_SPI_MOSI, X_NUCLEO_IHM02A1_PIN_SPI_MISO, X_NUCLEO_IHM02A1_PIN_SPI_SCLK);
00240     }
00241 
00242      
00243 
00244     /* Instantiating the components. */
00245     /* ACTION 3 --------------------------------------------------------------*
00246      * Instantiate here the expansion board's components.                     *
00247      *                                                                        *
00248      * Example:                                                               *
00249      *   component_1 = new COMPONENT_1(ssel, *dev_spi);                       *
00250      *   component_2 = new COMPONENT_2(ssel, *dev_spi);                       *
00251      *------------------------------------------------------------------------*/
00252     components[0] = l6470_0 = new L6470B(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00253     components[1] = l6470_1 = new L6470B(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00254     
00255     /* Initializing the components. */
00256     init_components[0] = init_0;
00257     init_components[1] = init_1;
00258     if (!init()) {
00259         error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
00260     }
00261 }
00262 
00263 /**
00264  * @brief Constructor.
00265  * @param init_0        pointer to the initialization structure of the first motor.
00266  * @param init_1        pointer to the initialization structure of the second motor.
00267  * @param flag_irq      pin name of the FLAG pin of the component.
00268  * @param busy_irq      pin name of the BUSY pin of the component.
00269  * @param standby_reset pin name of the STBY\RST pin of the component.
00270  * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
00271  * @param mosi          pin name of the MOSI pin of the SPI device to be used for communication.
00272  * @param miso          pin name of the MISO pin of the SPI device to be used for communication.
00273  * @param sclk          pin name of the SCLK pin of the SPI device to be used for communication.
00274  */
00275 XNucleoIHM02A12::XNucleoIHM02A12(L6470_init_t *init_0, L6470_init_t *init_1, PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, PinName mosi, PinName miso, PinName sclk)
00276 {
00277     /* Checking stackability. */
00278     if (!(number_of_boards1 < EXPBRD_MOUNTED_NR_MAX)) {
00279         error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
00280     }
00281     instance_id = number_of_boards1++;
00282     
00283     printf("--> so viele boards %d.\r\n",number_of_boards1);
00284     
00285     /* SPI communication. */
00286     dev_spi = new DevSPI(mosi, miso, sclk);
00287 
00288     /* Instantiating the components. */
00289     /* ACTION 3 --------------------------------------------------------------*
00290      * Instantiate here the expansion board's components.                     *
00291      *                                                                        *
00292      * Example:                                                               *
00293      *   component_1 = new COMPONENT_1(ssel, *dev_spi);                       *
00294      *   component_2 = new COMPONENT_2(ssel, *dev_spi);                       *
00295      *------------------------------------------------------------------------*/
00296     components[0] = l6470_0 = new L6470B(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00297     components[1] = l6470_1 = new L6470B(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
00298 
00299     /* Initializing the components. */
00300     init_components[0] = init_0;
00301     init_components[1] = init_1;
00302     if (!init()) {
00303         error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
00304     }
00305 }
00306 
00307 /**
00308  * @brief Initializing the X_NUCLEO_IHM02A1 board.
00309  * @retval true if initialization is successful, false otherwise.
00310  */
00311 bool XNucleoIHM02A12::init(void)
00312 {
00313     /* Initializing the components. */
00314     /* ACTION 4 --------------------------------------------------------------*
00315      * Initialize here the expansion board's components.                      *
00316      *                                                                        *
00317      * Example:                                                               *
00318      *   return (init_COMPONENT_1() && init_COMPONENT_2());                   *
00319      *------------------------------------------------------------------------*/
00320     return (init_L6470_0() && init_L6470_1());
00321 }
00322 
00323 /* ACTION 5 ------------------------------------------------------------------*
00324  * Implement here an initialization method for each expansion board's         *
00325  * component.                                                                 *
00326  *                                                                            *
00327  * Example:                                                                   *
00328  *   bool ExpansionBoard::init_COMPONENT_1(void)                              *
00329  *   {                                                                        *
00330  *     // Verifying identity.                                                 *
00331  *     uint8_t id = 0;                                                        *
00332  *     int ret = component_1->read_id(&id);                                   *
00333  *     if ((ret != COMPONENT_OK) || (id != I_AM_COMPONENT_1))                 *
00334  *     {                                                                      *
00335  *       delete component_1;                                                  *
00336  *       component_1 = NULL;                                                  *
00337  *       return true;                                                         *
00338  *     }                                                                      *
00339  *                                                                            *
00340  *     // Configuration.                                                      *
00341  *     COMPONENT_init_t init;                                                 *
00342  *     init.property_1 = COMPONENT_1_PROPERY_1_INIT;                          *
00343  *     init.property_N = COMPONENT_1_PROPERY_N_INIT;                          *
00344  *                                                                            *
00345  *     // Initialization.                                                     *
00346  *     if (component_1->init(&init) != COMPONENT_OK)                          *
00347  *       return false;                                                        *
00348  *                                                                            *
00349  *     return true;                                                           *
00350  *   }                                                                        *
00351  *----------------------------------------------------------------------------*/
00352 /**
00353  * @brief  Initialize the L6470 component.
00354  * @retval true if initialization is successful, false otherwise.
00355  */
00356 bool XNucleoIHM02A12::init_L6470_0(void)
00357 {
00358     /* Initialization. */
00359     if (l6470_0->init((void *) init_components[0]) != COMPONENT_OK) {
00360         return false;
00361     }
00362 
00363     return true;
00364 }
00365 
00366 /**
00367  * @brief  Initialize the L6470 component.
00368  * @retval true if initialization is successful, false otherwise.
00369  */
00370 bool XNucleoIHM02A12::init_L6470_1(void)
00371 {
00372     /* Initialization. */
00373     if (l6470_1->init((void *) init_components[1]) != COMPONENT_OK) {
00374         return false;
00375     }
00376 
00377     return true;
00378 }
00379 
00380 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/