Tom STOGIANNIS / Mbed OS HelloWorld_IHM02A1-2

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Committer:
tomstogiannis
Date:
Thu Dec 17 14:58:10 2020 +0000
Revision:
29:523fea76d664
change wait_ms to wait_us

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomstogiannis 29:523fea76d664 1 /**
tomstogiannis 29:523fea76d664 2 ******************************************************************************
tomstogiannis 29:523fea76d664 3 * @file XNucleoIHM02A1.cpp
tomstogiannis 29:523fea76d664 4 * @author AST / Software Platforms and Cloud
tomstogiannis 29:523fea76d664 5 * @version V1.0
tomstogiannis 29:523fea76d664 6 * @date November 3rd, 2015
tomstogiannis 29:523fea76d664 7 * @brief Implementation file for the X_NUCLEO_IHM02A1 expansion board.
tomstogiannis 29:523fea76d664 8 ******************************************************************************
tomstogiannis 29:523fea76d664 9 * @attention
tomstogiannis 29:523fea76d664 10 *
tomstogiannis 29:523fea76d664 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
tomstogiannis 29:523fea76d664 12 *
tomstogiannis 29:523fea76d664 13 * Redistribution and use in source and binary forms, with or without modification,
tomstogiannis 29:523fea76d664 14 * are permitted provided that the following conditions are met:
tomstogiannis 29:523fea76d664 15 * 1. Redistributions of source code must retain the above copyright notice,
tomstogiannis 29:523fea76d664 16 * this list of conditions and the following disclaimer.
tomstogiannis 29:523fea76d664 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
tomstogiannis 29:523fea76d664 18 * this list of conditions and the following disclaimer in the documentation
tomstogiannis 29:523fea76d664 19 * and/or other materials provided with the distribution.
tomstogiannis 29:523fea76d664 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
tomstogiannis 29:523fea76d664 21 * may be used to endorse or promote products derived from this software
tomstogiannis 29:523fea76d664 22 * without specific prior written permission.
tomstogiannis 29:523fea76d664 23 *
tomstogiannis 29:523fea76d664 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
tomstogiannis 29:523fea76d664 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
tomstogiannis 29:523fea76d664 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
tomstogiannis 29:523fea76d664 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
tomstogiannis 29:523fea76d664 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
tomstogiannis 29:523fea76d664 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
tomstogiannis 29:523fea76d664 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
tomstogiannis 29:523fea76d664 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
tomstogiannis 29:523fea76d664 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
tomstogiannis 29:523fea76d664 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tomstogiannis 29:523fea76d664 34 *
tomstogiannis 29:523fea76d664 35 ******************************************************************************
tomstogiannis 29:523fea76d664 36 */
tomstogiannis 29:523fea76d664 37
tomstogiannis 29:523fea76d664 38
tomstogiannis 29:523fea76d664 39 /* Generated with STM32CubeTOO -----------------------------------------------*/
tomstogiannis 29:523fea76d664 40
tomstogiannis 29:523fea76d664 41
tomstogiannis 29:523fea76d664 42 /* Includes ------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 43
tomstogiannis 29:523fea76d664 44 /* ACTION 1 ------------------------------------------------------------------*
tomstogiannis 29:523fea76d664 45 * Include here platform specific header files. *
tomstogiannis 29:523fea76d664 46 *----------------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 47 #include "mbed.h"
tomstogiannis 29:523fea76d664 48 #include "DevSPI.h"
tomstogiannis 29:523fea76d664 49 /* ACTION 2 ------------------------------------------------------------------*
tomstogiannis 29:523fea76d664 50 * Include here expansion board specific header files. *
tomstogiannis 29:523fea76d664 51 *----------------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 52 #include "XNucleoIHM02A1.h"
tomstogiannis 29:523fea76d664 53
tomstogiannis 29:523fea76d664 54
tomstogiannis 29:523fea76d664 55 /* Variables -----------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 56
tomstogiannis 29:523fea76d664 57 /* Number of expansion boards. */
tomstogiannis 29:523fea76d664 58 uint8_t XNucleoIHM02A1::number_of_boards = 0;
tomstogiannis 29:523fea76d664 59
tomstogiannis 29:523fea76d664 60
tomstogiannis 29:523fea76d664 61 /* Methods -------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 62
tomstogiannis 29:523fea76d664 63 /**
tomstogiannis 29:523fea76d664 64 * @brief Constructor.
tomstogiannis 29:523fea76d664 65 * @param init_0 pointer to the initialization structure of the first motor.
tomstogiannis 29:523fea76d664 66 * @param init_1 pointer to the initialization structure of the second motor.
tomstogiannis 29:523fea76d664 67 * @param flag_irq pin name of the FLAG pin of the component.
tomstogiannis 29:523fea76d664 68 * @param busy_irq pin name of the BUSY pin of the component.
tomstogiannis 29:523fea76d664 69 * @param standby_reset pin name of the STBY\RST pin of the component.
tomstogiannis 29:523fea76d664 70 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication.
tomstogiannis 29:523fea76d664 71 * @param spi SPI device to be used for communication.
tomstogiannis 29:523fea76d664 72 */
tomstogiannis 29:523fea76d664 73 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)
tomstogiannis 29:523fea76d664 74 {
tomstogiannis 29:523fea76d664 75 /* Checking stackability. */
tomstogiannis 29:523fea76d664 76 if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX)) {
tomstogiannis 29:523fea76d664 77 error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
tomstogiannis 29:523fea76d664 78 }
tomstogiannis 29:523fea76d664 79 instance_id = number_of_boards++;
tomstogiannis 29:523fea76d664 80
tomstogiannis 29:523fea76d664 81 /* SPI communication. */
tomstogiannis 29:523fea76d664 82 if (dev_spi == NULL) {
tomstogiannis 29:523fea76d664 83 dev_spi = new DevSPI(X_NUCLEO_IHM02A1_PIN_SPI_MOSI, X_NUCLEO_IHM02A1_PIN_SPI_MISO, X_NUCLEO_IHM02A1_PIN_SPI_SCLK);
tomstogiannis 29:523fea76d664 84 }
tomstogiannis 29:523fea76d664 85
tomstogiannis 29:523fea76d664 86 /* Instantiating the components. */
tomstogiannis 29:523fea76d664 87 /* ACTION 3 --------------------------------------------------------------*
tomstogiannis 29:523fea76d664 88 * Instantiate here the expansion board's components. *
tomstogiannis 29:523fea76d664 89 * *
tomstogiannis 29:523fea76d664 90 * Example: *
tomstogiannis 29:523fea76d664 91 * component_1 = new COMPONENT_1(ssel, *dev_spi); *
tomstogiannis 29:523fea76d664 92 * component_2 = new COMPONENT_2(ssel, *dev_spi); *
tomstogiannis 29:523fea76d664 93 *------------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 94 components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
tomstogiannis 29:523fea76d664 95 components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
tomstogiannis 29:523fea76d664 96
tomstogiannis 29:523fea76d664 97 /* Initializing the components. */
tomstogiannis 29:523fea76d664 98 init_components[0] = init_0;
tomstogiannis 29:523fea76d664 99 init_components[1] = init_1;
tomstogiannis 29:523fea76d664 100 if (!init()) {
tomstogiannis 29:523fea76d664 101 error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
tomstogiannis 29:523fea76d664 102 }
tomstogiannis 29:523fea76d664 103 }
tomstogiannis 29:523fea76d664 104
tomstogiannis 29:523fea76d664 105 /**
tomstogiannis 29:523fea76d664 106 * @brief Constructor.
tomstogiannis 29:523fea76d664 107 * @param init_0 pointer to the initialization structure of the first motor.
tomstogiannis 29:523fea76d664 108 * @param init_1 pointer to the initialization structure of the second motor.
tomstogiannis 29:523fea76d664 109 * @param flag_irq pin name of the FLAG pin of the component.
tomstogiannis 29:523fea76d664 110 * @param busy_irq pin name of the BUSY pin of the component.
tomstogiannis 29:523fea76d664 111 * @param standby_reset pin name of the STBY\RST pin of the component.
tomstogiannis 29:523fea76d664 112 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication.
tomstogiannis 29:523fea76d664 113 * @param mosi pin name of the MOSI pin of the SPI device to be used for communication.
tomstogiannis 29:523fea76d664 114 * @param miso pin name of the MISO pin of the SPI device to be used for communication.
tomstogiannis 29:523fea76d664 115 * @param sclk pin name of the SCLK pin of the SPI device to be used for communication.
tomstogiannis 29:523fea76d664 116 */
tomstogiannis 29:523fea76d664 117 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)
tomstogiannis 29:523fea76d664 118 {
tomstogiannis 29:523fea76d664 119 /* Checking stackability. */
tomstogiannis 29:523fea76d664 120 if (!(number_of_boards < EXPBRD_MOUNTED_NR_MAX)) {
tomstogiannis 29:523fea76d664 121 error("Instantiation of the X_NUCLEO_IHM02A1 expansion board failed: it can be stacked up to %d times.\r\n", EXPBRD_MOUNTED_NR_MAX);
tomstogiannis 29:523fea76d664 122 }
tomstogiannis 29:523fea76d664 123 instance_id = number_of_boards++;
tomstogiannis 29:523fea76d664 124
tomstogiannis 29:523fea76d664 125 /* SPI communication. */
tomstogiannis 29:523fea76d664 126 dev_spi = new DevSPI(mosi, miso, sclk);
tomstogiannis 29:523fea76d664 127
tomstogiannis 29:523fea76d664 128 /* Instantiating the components. */
tomstogiannis 29:523fea76d664 129 /* ACTION 3 --------------------------------------------------------------*
tomstogiannis 29:523fea76d664 130 * Instantiate here the expansion board's components. *
tomstogiannis 29:523fea76d664 131 * *
tomstogiannis 29:523fea76d664 132 * Example: *
tomstogiannis 29:523fea76d664 133 * component_1 = new COMPONENT_1(ssel, *dev_spi); *
tomstogiannis 29:523fea76d664 134 * component_2 = new COMPONENT_2(ssel, *dev_spi); *
tomstogiannis 29:523fea76d664 135 *------------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 136 components[0] = l6470_0 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
tomstogiannis 29:523fea76d664 137 components[1] = l6470_1 = new L6470(flag_irq, busy_irq, standby_reset, ssel, *dev_spi);
tomstogiannis 29:523fea76d664 138
tomstogiannis 29:523fea76d664 139 /* Initializing the components. */
tomstogiannis 29:523fea76d664 140 init_components[0] = init_0;
tomstogiannis 29:523fea76d664 141 init_components[1] = init_1;
tomstogiannis 29:523fea76d664 142 if (!init()) {
tomstogiannis 29:523fea76d664 143 error("Initialization of the X_NUCLEO_IHM02A1 expansion board failed.\r\n");
tomstogiannis 29:523fea76d664 144 }
tomstogiannis 29:523fea76d664 145 }
tomstogiannis 29:523fea76d664 146
tomstogiannis 29:523fea76d664 147 /**
tomstogiannis 29:523fea76d664 148 * @brief Initializing the X_NUCLEO_IHM02A1 board.
tomstogiannis 29:523fea76d664 149 * @retval true if initialization is successful, false otherwise.
tomstogiannis 29:523fea76d664 150 */
tomstogiannis 29:523fea76d664 151 bool XNucleoIHM02A1::init(void)
tomstogiannis 29:523fea76d664 152 {
tomstogiannis 29:523fea76d664 153 /* Initializing the components. */
tomstogiannis 29:523fea76d664 154 /* ACTION 4 --------------------------------------------------------------*
tomstogiannis 29:523fea76d664 155 * Initialize here the expansion board's components. *
tomstogiannis 29:523fea76d664 156 * *
tomstogiannis 29:523fea76d664 157 * Example: *
tomstogiannis 29:523fea76d664 158 * return (init_COMPONENT_1() && init_COMPONENT_2()); *
tomstogiannis 29:523fea76d664 159 *------------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 160 return (init_L6470_0() && init_L6470_1());
tomstogiannis 29:523fea76d664 161 }
tomstogiannis 29:523fea76d664 162
tomstogiannis 29:523fea76d664 163 /* ACTION 5 ------------------------------------------------------------------*
tomstogiannis 29:523fea76d664 164 * Implement here an initialization method for each expansion board's *
tomstogiannis 29:523fea76d664 165 * component. *
tomstogiannis 29:523fea76d664 166 * *
tomstogiannis 29:523fea76d664 167 * Example: *
tomstogiannis 29:523fea76d664 168 * bool ExpansionBoard::init_COMPONENT_1(void) *
tomstogiannis 29:523fea76d664 169 * { *
tomstogiannis 29:523fea76d664 170 * // Verifying identity. *
tomstogiannis 29:523fea76d664 171 * uint8_t id = 0; *
tomstogiannis 29:523fea76d664 172 * int ret = component_1->read_id(&id); *
tomstogiannis 29:523fea76d664 173 * if ((ret != COMPONENT_OK) || (id != I_AM_COMPONENT_1)) *
tomstogiannis 29:523fea76d664 174 * { *
tomstogiannis 29:523fea76d664 175 * delete component_1; *
tomstogiannis 29:523fea76d664 176 * component_1 = NULL; *
tomstogiannis 29:523fea76d664 177 * return true; *
tomstogiannis 29:523fea76d664 178 * } *
tomstogiannis 29:523fea76d664 179 * *
tomstogiannis 29:523fea76d664 180 * // Configuration. *
tomstogiannis 29:523fea76d664 181 * COMPONENT_init_t init; *
tomstogiannis 29:523fea76d664 182 * init.property_1 = COMPONENT_1_PROPERY_1_INIT; *
tomstogiannis 29:523fea76d664 183 * init.property_N = COMPONENT_1_PROPERY_N_INIT; *
tomstogiannis 29:523fea76d664 184 * *
tomstogiannis 29:523fea76d664 185 * // Initialization. *
tomstogiannis 29:523fea76d664 186 * if (component_1->init(&init) != COMPONENT_OK) *
tomstogiannis 29:523fea76d664 187 * return false; *
tomstogiannis 29:523fea76d664 188 * *
tomstogiannis 29:523fea76d664 189 * return true; *
tomstogiannis 29:523fea76d664 190 * } *
tomstogiannis 29:523fea76d664 191 *----------------------------------------------------------------------------*/
tomstogiannis 29:523fea76d664 192 /**
tomstogiannis 29:523fea76d664 193 * @brief Initialize the L6470 component.
tomstogiannis 29:523fea76d664 194 * @retval true if initialization is successful, false otherwise.
tomstogiannis 29:523fea76d664 195 */
tomstogiannis 29:523fea76d664 196 bool XNucleoIHM02A1::init_L6470_0(void)
tomstogiannis 29:523fea76d664 197 {
tomstogiannis 29:523fea76d664 198 /* Initialization. */
tomstogiannis 29:523fea76d664 199 if (l6470_0->init((void *) init_components[0]) != COMPONENT_OK) {
tomstogiannis 29:523fea76d664 200 return false;
tomstogiannis 29:523fea76d664 201 }
tomstogiannis 29:523fea76d664 202
tomstogiannis 29:523fea76d664 203 return true;
tomstogiannis 29:523fea76d664 204 }
tomstogiannis 29:523fea76d664 205
tomstogiannis 29:523fea76d664 206 /**
tomstogiannis 29:523fea76d664 207 * @brief Initialize the L6470 component.
tomstogiannis 29:523fea76d664 208 * @retval true if initialization is successful, false otherwise.
tomstogiannis 29:523fea76d664 209 */
tomstogiannis 29:523fea76d664 210 bool XNucleoIHM02A1::init_L6470_1(void)
tomstogiannis 29:523fea76d664 211 {
tomstogiannis 29:523fea76d664 212 /* Initialization. */
tomstogiannis 29:523fea76d664 213 if (l6470_1->init((void *) init_components[1]) != COMPONENT_OK) {
tomstogiannis 29:523fea76d664 214 return false;
tomstogiannis 29:523fea76d664 215 }
tomstogiannis 29:523fea76d664 216
tomstogiannis 29:523fea76d664 217 return true;
tomstogiannis 29:523fea76d664 218 }
tomstogiannis 29:523fea76d664 219
tomstogiannis 29:523fea76d664 220 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/