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
XNucleoIHM02A1.cpp
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>© 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 00060 00061 /* Methods -------------------------------------------------------------------*/ 00062 00063 /** 00064 * @brief Constructor. 00065 * @param init_0 pointer to the initialization structure of the first motor. 00066 * @param init_1 pointer to the initialization structure of the second motor. 00067 * @param flag_irq pin name of the FLAG pin of the component. 00068 * @param busy_irq pin name of the BUSY pin of the component. 00069 * @param standby_reset pin name of the STBY\RST pin of the component. 00070 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication. 00071 * @param spi SPI device to be used for communication. 00072 */ 00073 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) 00074 { 00075 /* Checking stackability. */ 00076 if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX)) { 00077 error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX); 00078 } 00079 instance_id = number_of_boards++; 00080 00081 /* SPI communication. */ 00082 if (dev_spi == NULL) { 00083 dev_spi = new DevSPI(X_NUCLEO_IHM02A1_PIN_SPI_MOSI, X_NUCLEO_IHM02A1_PIN_SPI_MISO, X_NUCLEO_IHM02A1_PIN_SPI_SCLK); 00084 } 00085 00086 /* Instantiating the components. */ 00087 /* ACTION 3 --------------------------------------------------------------* 00088 * Instantiate here the expansion board's components. * 00089 * * 00090 * Example: * 00091 * component_1 = new COMPONENT_1(ssel, *dev_spi); * 00092 * component_2 = new COMPONENT_2(ssel, *dev_spi); * 00093 *------------------------------------------------------------------------*/ 00094 components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi); 00095 components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi); 00096 00097 /* Initializing the components. */ 00098 init_components[0] = init_0; 00099 init_components[1] = init_1; 00100 if (!init()) { 00101 error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n"); 00102 } 00103 } 00104 00105 /** 00106 * @brief Constructor. 00107 * @param init_0 pointer to the initialization structure of the first motor. 00108 * @param init_1 pointer to the initialization structure of the second motor. 00109 * @param flag_irq pin name of the FLAG pin of the component. 00110 * @param busy_irq pin name of the BUSY pin of the component. 00111 * @param standby_reset pin name of the STBY\RST pin of the component. 00112 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication. 00113 * @param mosi pin name of the MOSI pin of the SPI device to be used for communication. 00114 * @param miso pin name of the MISO pin of the SPI device to be used for communication. 00115 * @param sclk pin name of the SCLK pin of the SPI device to be used for communication. 00116 */ 00117 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) 00118 { 00119 /* Checking stackability. */ 00120 if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX)) { 00121 error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX); 00122 } 00123 instance_id = number_of_boards++; 00124 00125 /* SPI communication. */ 00126 dev_spi = new DevSPI(mosi, miso, sclk); 00127 00128 /* Instantiating the components. */ 00129 /* ACTION 3 --------------------------------------------------------------* 00130 * Instantiate here the expansion board's components. * 00131 * * 00132 * Example: * 00133 * component_1 = new COMPONENT_1(ssel, *dev_spi); * 00134 * component_2 = new COMPONENT_2(ssel, *dev_spi); * 00135 *------------------------------------------------------------------------*/ 00136 components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi); 00137 components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi); 00138 00139 /* Initializing the components. */ 00140 init_components[0] = init_0; 00141 init_components[1] = init_1; 00142 if (!init()) { 00143 error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n"); 00144 } 00145 } 00146 00147 /** 00148 * @brief Initializing the X_NUCLEO_IHM02A1 board. 00149 * @retval true if initialization is successful, false otherwise. 00150 */ 00151 bool XNucleoIHM02A1::init(void) 00152 { 00153 /* Initializing the components. */ 00154 /* ACTION 4 --------------------------------------------------------------* 00155 * Initialize here the expansion board's components. * 00156 * * 00157 * Example: * 00158 * return (init_COMPONENT_1() && init_COMPONENT_2()); * 00159 *------------------------------------------------------------------------*/ 00160 return (init_L6470_0() && init_L6470_1()); 00161 } 00162 00163 /* ACTION 5 ------------------------------------------------------------------* 00164 * Implement here an initialization method for each expansion board's * 00165 * component. * 00166 * * 00167 * Example: * 00168 * bool ExpansionBoard::init_COMPONENT_1(void) * 00169 * { * 00170 * // Verifying identity. * 00171 * uint8_t id = 0; * 00172 * int ret = component_1->read_id(&id); * 00173 * if ((ret != COMPONENT_OK) || (id != I_AM_COMPONENT_1)) * 00174 * { * 00175 * delete component_1; * 00176 * component_1 = NULL; * 00177 * return true; * 00178 * } * 00179 * * 00180 * // Configuration. * 00181 * COMPONENT_init_t init; * 00182 * init.property_1 = COMPONENT_1_PROPERY_1_INIT; * 00183 * init.property_N = COMPONENT_1_PROPERY_N_INIT; * 00184 * * 00185 * // Initialization. * 00186 * if (component_1->init(&init) != COMPONENT_OK) * 00187 * return false; * 00188 * * 00189 * return true; * 00190 * } * 00191 *----------------------------------------------------------------------------*/ 00192 /** 00193 * @brief Initialize the L6470 component. 00194 * @retval true if initialization is successful, false otherwise. 00195 */ 00196 bool XNucleoIHM02A1::init_L6470_0(void) 00197 { 00198 /* Initialization. */ 00199 if (l6470_0->init((void *) init_components[0]) != COMPONENT_OK) { 00200 return false; 00201 } 00202 00203 return true; 00204 } 00205 00206 /** 00207 * @brief Initialize the L6470 component. 00208 * @retval true if initialization is successful, false otherwise. 00209 */ 00210 bool XNucleoIHM02A1::init_L6470_1(void) 00211 { 00212 /* Initialization. */ 00213 if (l6470_1->init((void *) init_components[1]) != COMPONENT_OK) { 00214 return false; 00215 } 00216 00217 return true; 00218 } 00219 00220 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 22:48:07 by 1.7.2