hi
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IHM02A1 by
Components/L6470/L6470.cpp@25:e7bdebda3c3b, 2018-02-01 (annotated)
- Committer:
- barry210110
- Date:
- Thu Feb 01 07:31:24 2018 +0000
- Revision:
- 25:e7bdebda3c3b
- Parent:
- 23:cf489f2ab072
hi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 2 | ****************************************************************************** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 3 | * @file l6470_class.cpp |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 4 | * @date 01/10/2014 12:00:00 |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 5 | * @brief This file provides set of firmware functions to manage the |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 6 | * L6470. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 7 | ****************************************************************************** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 8 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 9 | * COPYRIGHT(c) 2014 STMicroelectronics |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 10 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 11 | * Redistribution and use in source and binary forms, with or without modification, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 12 | * are permitted provided that the following conditions are met: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 13 | * 1. Redistributions of source code must retain the above copyright notice, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 14 | * this list of conditions and the following disclaimer. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 16 | * this list of conditions and the following disclaimer in the documentation |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 17 | * and/or other materials provided with the distribution. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 19 | * may be used to endorse or promote products derived from this software |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 20 | * without specific prior written permission. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 21 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 32 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 33 | ****************************************************************************** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 34 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 35 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 36 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 37 | /* Generated with STM32CubeTOO -----------------------------------------------*/ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 38 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 39 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 40 | /* Revision ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 41 | /* |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 42 | Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 43 | Branch/Trunk/Tag: trunk |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 44 | Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.c |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 45 | Revision: 0 |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 46 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 47 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 48 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 49 | /* Includes ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 50 | |
Davidroid | 23:cf489f2ab072 | 51 | #include "L6470.h" |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 52 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 53 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 54 | /* Variables -----------------------------------------------------------------*/ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 55 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 56 | /* Number of instantiated devices on an expansion board. */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 57 | uint8_t L6470::number_of_devices = 0; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 58 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 59 | /* SPI Transmission for Daisy-Chain Configuration. */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 60 | eFlagStatus_t L6470::L6470_DaisyChain_HalfPrepared; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 61 | sL6470_AppCmdPkg_t L6470::L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 62 | uint8_t L6470::L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 63 | uint8_t L6470::L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 64 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 65 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 66 | * @brief Array whose elements are a structure in which store information about |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 67 | * the L6470 Registers (the address, the names, the length in bits, the |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 68 | * reset value) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 69 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 70 | const sL6470_Register_t L6470::_L6470_Register[L6470REGIDSIZE] = { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 71 | {0x01 , "ABS_POS", 22, 3, 0x000000}, //!< Current position |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 72 | {0x02 , "EL_POS", 9, 2, 0x000}, //!< Electrical position |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 73 | {0x03 , "MARK", 22, 3, 0x000000}, //!< Mark position |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 74 | {0x04 , "SPEED", 20, 3, 0x0000}, //!< Current speed |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 75 | {0x05 , "ACC", 12, 2, 0x08A}, //!< Acceleration |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 76 | {0x06 , "DEC", 12, 2, 0x08A}, //!< Deceleration |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 77 | {0x07 , "MAX_SPEED", 10, 2, 0x041}, //!< Maximum speed |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 78 | {0x08 , "MIN_SPEED", 13, 2, 0x000}, //!< Minimum speed |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 79 | {0x15 , "FS_SPD", 10, 2, 0x027}, //!< Full-step speed |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 80 | {0x09 , "KVAL_HOLD", 8, 1, 0x29}, //!< Holding KVAL |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 81 | {0x0A , "KVAL_RUN", 8, 1, 0x29}, //!< Constant speed KVAL |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 82 | {0x0B , "KVAL_ACC", 8, 1, 0x29}, //!< Acceleration starting KVAL |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 83 | {0x0C , "KVAL_DEC", 8, 1, 0x29}, //!< Deceleration starting KVAL |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 84 | {0x0D , "INT_SPEED", 14, 2, 0x0408}, //!< Intersect speed |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 85 | {0x0E , "ST_SLP", 8, 1, 0x19}, //!< Start slope |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 86 | {0x0F , "FN_SLP_ACC", 8, 1, 0x29}, //!< Acceleration final slope |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 87 | {0x10 , "FN_SLP_DEC", 8, 1, 0x29}, //!< Deceleration final slope |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 88 | {0x11 , "K_THERM", 4, 1, 0x0}, //!< Thermal compensation factor |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 89 | {0x12 , "ADC_OUT", 5, 1, 0x00}, //!< ADC output, (the reset value is according to startup conditions) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 90 | {0x13 , "OCD_TH", 4, 1, 0x8}, //!< OCD threshold |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 91 | {0x14 , "STALL_TH", 7, 1, 0x40}, //!< STALL threshold |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 92 | {0x16 , "STEP_MODE", 8, 1, 0x7}, //!< Step mode |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 93 | {0x17 , "ALARM_EN", 8, 1, 0xFF}, //!< Alarm enable |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 94 | {0x18 , "CONFIG", 16, 2, 0x2E88}, //!< IC configuration |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 95 | {0x19 , "STATUS", 16, 2, 0x0000} //!< Status, (the reset value is according to startup conditions) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 96 | }; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 97 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 98 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 99 | * @brief Array whose elements are a structure in which store information about |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 100 | * the L6470 Application Commands (the mnemonic name, the number of |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 101 | * needed parameters, the related funtion to call) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 102 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 103 | const sL6470_ApplicationCommand_t L6470::_L6470_ApplicationCommand[L6470APPCMDIDSIZE] = { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 104 | {"NOP", 0x00, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 105 | {"SETPARAM", 0x00, 2}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 106 | {"GETPARAM", 0x20, 1}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 107 | {"RUN", 0x50, 2}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 108 | {"STEPCLOCK", 0x58, 1}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 109 | {"MOVE", 0x40, 2}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 110 | {"GOTO", 0x60, 1}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 111 | {"GOTO_DIR", 0x68, 2}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 112 | {"GOUNTIL", 0x82, 3}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 113 | {"RELEASESW", 0x92, 2}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 114 | {"GOHOME", 0x70, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 115 | {"GOMARK", 0x78, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 116 | {"RESETPOS", 0xD8, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 117 | {"RESETDEVICE", 0xC0, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 118 | {"SOFTSTOP", 0xB0, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 119 | {"HARDSTOP", 0xB8, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 120 | {"SOFTHIZ", 0xA0, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 121 | {"HARDHIZ", 0xA8, 0}, |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 122 | {"GETSTATUS", 0xD0, 0} |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 123 | }; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 124 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 125 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 126 | * @brief The mnemonic names for the L6470 direction |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 127 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 128 | const sL6470_Direction_t L6470::_L6470_Direction[L6470DIRIDSIZE] = { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 129 | {"REV", 0x00}, //!< Reverse direction |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 130 | {"FWD", 0x01} //!< Forward direction |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 131 | }; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 132 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 133 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 134 | * @brief Action taken about ABS_POS register |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 135 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 136 | const sL6470_ACT_t L6470::_L6470_ACT[L6470ACTIDSIZE] = { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 137 | {"RST", 0x00}, //!< ABS_POS register is reset |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 138 | {"CPY", 0x01} //!< ABS_POS register value is copied into the MARK register |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 139 | }; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 140 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 141 | /* End of L6470_Private_Constants */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 142 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 143 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 144 | * @defgroup L6470_Private_Variables |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 145 | * @brief L6470 Private Variables. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 146 | * @{ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 147 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 148 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 149 | /* End of L6470_Private_Variables */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 150 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 151 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 152 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 153 | * @addtogroup L6470_Private_Functions |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 154 | * @{ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 155 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 156 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 157 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 158 | /* Methods -------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 159 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 160 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 161 | * @brief Reset the structure used to store the identifier of the L6470 |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 162 | * application command and its the needed parameters. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 163 | * @param pL6470_AppCmdPkg The structure to be reset. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 164 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 165 | void L6470::L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 166 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 167 | uint8_t id; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 168 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 169 | for(id=0; id<L6470DAISYCHAINSIZE; id++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 170 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 171 | (pL6470_AppCmdPkg+id)->L6470_AppCmdId=(eL6470_AppCmdId_t)0; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 172 | (pL6470_AppCmdPkg+id)->p1=0; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 173 | (pL6470_AppCmdPkg+id)->p2=0; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 174 | (pL6470_AppCmdPkg+id)->p3=0; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 175 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 176 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 177 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 178 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 179 | * @brief Fill the structure used to store the identifier of the L6470 |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 180 | * application command and its the needed parameters. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 181 | * @param L6470_Id The identifier of the L6470 target inside the daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 182 | * @param pL6470_AppCmdPkg The structure to be filled. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 183 | * @param L6470_AppCmdId The identifier of the L6470 application command to be sent. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 184 | * @param p1 The 1st parameter (if it is not needed it will be not considered). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 185 | * @param p2 The 2nd parameter (if it is not needed it will be not considered). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 186 | * @param p3 The 3rd parameter (if it is not needed it will be not considered). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 187 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 188 | void L6470::L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 189 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 190 | (pL6470_AppCmdPkg+L6470_Id)->L6470_AppCmdId = L6470_AppCmdId; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 191 | (pL6470_AppCmdPkg+L6470_Id)->p1 = p1; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 192 | (pL6470_AppCmdPkg+L6470_Id)->p2 = p2; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 193 | (pL6470_AppCmdPkg+L6470_Id)->p3 = p3; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 194 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 195 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 196 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 197 | * @brief This function will fill the column of the L6470_AppCmdPkg related |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 198 | * the L6470 to be addressed inside the daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 199 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 200 | * @param L6470_Id The identifier of the L6470 target inside the daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 201 | * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 202 | * @param L6470_AppCmdId The identifier of the L6470 application command to be sent. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 203 | * @param p1 The 1st parameter (if it is not needed it will be not considered). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 204 | * @param p2 The 2nd parameter (if it is not needed it will be not considered). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 205 | * @param p3 The 3rd parameter (if it is not needed it will be not considered). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 206 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 207 | void L6470::L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 208 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 209 | if(!L6470_DaisyChain_HalfPrepared) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 210 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 211 | L6470_DaisyChain_HalfPrepared = ONE_F; /* To avoid to delete the previous entered command */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 212 | L6470_ResetAppCmdPkg(pL6470_AppCmdPkg); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 213 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 214 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 215 | L6470_FillAppCmdPkg(pL6470_AppCmdPkg, L6470_AppCmdId, p1, p2, p3); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 216 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 217 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 218 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 219 | * @brief This function will translate the data inside the L6470_AppCmdPkg into |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 220 | * the right data to be sent via SPI to the L6470 daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 221 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 222 | * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 223 | * @param pL6470_DaisyChainSpiTxStruct Pointer to the structure used by SPI to send the commands. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 224 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 225 | void L6470::L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 226 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 227 | uint8_t PkgId; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 228 | uint8_t PARAMLengthBytes; /* The number of bytes related to the numeric value for the addressed register */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 229 | uint8_t spibyte; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 230 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 231 | /* Reset the structure used to send the command to the L6470 Daisy Chain through the SPI */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 232 | uint8_t i = 0; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 233 | for(spibyte=0;spibyte<L6470MAXSPICMDBYTESIZE;spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 234 | for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 235 | *(pL6470_DaisyChainSpiTxStruct+(i++)) = 0x00; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 236 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 237 | for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 238 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 239 | /* Build the 1st bytes to transmit with the binary code of the command */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 240 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) = (L6470_ApplicationCommand[(pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId].BinaryCode); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 241 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 242 | /* Perform the related L6470_AppCmdId */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 243 | switch((pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 244 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 245 | case L6470_NOP_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 246 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 247 | case L6470_SETPARAM_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 248 | /* Build the 1st bytes to transmit (PARAM) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 249 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 250 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 251 | /* The length, in byte, of this register (PARAM) is... */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 252 | PARAMLengthBytes = L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].LengthByte; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 253 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 254 | /* Build the others bytes to transmit (VALUE) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 255 | for (spibyte=1; spibyte<(PARAMLengthBytes+1); spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 256 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 257 | *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(PARAMLengthBytes-spibyte))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 258 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 259 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 260 | case L6470_GETPARAM_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 261 | /* Build the 1st bytes to transmit (PARAM) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 262 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 263 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 264 | case L6470_RUN_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 265 | /* Build the 1st bytes to transmit (DIR) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 266 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 267 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 268 | /* Build the others bytes to transmit (SPD) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 269 | for (spibyte=1; spibyte<(3+1); spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 270 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 271 | *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 272 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 273 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 274 | case L6470_STEPCLOCK_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 275 | /* Build the 1st bytes to transmit (DIR) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 276 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 277 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 278 | case L6470_MOVE_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 279 | /* Build the 1st bytes to transmit (DIR) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 280 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 281 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 282 | /* Build the others bytes to transmit (N_STEP) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 283 | for (spibyte=1; spibyte<(3+1); spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 284 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 285 | *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 286 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 287 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 288 | case L6470_GOTO_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 289 | /* Build the others bytes to transmit (ABS_POS) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 290 | for (spibyte=1; spibyte<(3+1); spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 291 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 292 | *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p1) >> (8*(3-spibyte))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 293 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 294 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 295 | case L6470_GOTODIR_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 296 | /* Build the 1st bytes to transmit (DIR) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 297 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 298 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 299 | /* Build the others bytes to transmit (ABS_POS) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 300 | for (spibyte=1; spibyte<(3+1); spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 301 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 302 | *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 303 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 304 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 305 | case L6470_GOUNTIL_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 306 | /* Build the 1st bytes to transmit (ACT) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 307 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 308 | /* Build the 1st bytes to transmit (DIR) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 309 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 310 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 311 | /* Build the others bytes to transmit (SPD) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 312 | for (spibyte=1; spibyte<(3+1); spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 313 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 314 | *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p3) >> (8*(3-spibyte))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 315 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 316 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 317 | case L6470_RELEASESW_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 318 | /* Build the 1st bytes to transmit (ACT) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 319 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 320 | /* Build the 1st bytes to transmit (DIR) */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 321 | *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 322 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 323 | case L6470_GOHOME_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 324 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 325 | case L6470_GOMARK_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 326 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 327 | case L6470_RESETPOS_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 328 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 329 | case L6470_RESETDEVICE_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 330 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 331 | case L6470_SOFTSTOP_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 332 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 333 | case L6470_HARDSTOP_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 334 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 335 | case L6470_SOFTHIZ_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 336 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 337 | case L6470_HARDHIZ_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 338 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 339 | case L6470_GETSTATUS_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 340 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 341 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 342 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 343 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 344 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 345 | /* End of L6470_Private_Functions */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 346 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 347 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 348 | * @addtogroup L6470_Exported_Functions |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 349 | * @{ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 350 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 351 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 352 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 353 | * @addtogroup L6470_Conversion_Functions |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 354 | * @brief The following functions act just on one driver inside the L6470 |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 355 | * daisy chain. The command is immediately sent. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 356 | * @{ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 357 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 358 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 359 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 360 | * @brief Convert the absolute position as 2's complement format into the signed number. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 361 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 362 | * @param AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1]. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 363 | * @retval Position The position as signed number. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 364 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 365 | int32_t L6470::L6470_AbsPos_2_Position(uint32_t AbsPos) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 366 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 367 | if (AbsPos > L6470_MAX_POSITION) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 368 | return (AbsPos - (L6470_POSITION_RANGE + 1)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 369 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 370 | return AbsPos; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 371 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 372 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 373 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 374 | * @brief Convert the position as signed number into absolute position as 2's complement format. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 375 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 376 | * @param Position The position as signed number. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 377 | * @retval AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1]. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 378 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 379 | uint32_t L6470::L6470_Position_2_AbsPos(int32_t Position) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 380 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 381 | if ((Position >= 0) && (Position <= L6470_MAX_POSITION)) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 382 | return Position; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 383 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 384 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 385 | if ((Position >= L6470_MIN_POSITION) && (Position < 0)) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 386 | return (Position + (L6470_POSITION_RANGE + 1)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 387 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 388 | return (L6470_POSITION_RANGE + 1); // OVF |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 389 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 390 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 391 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 392 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 393 | * @brief Convert the SPEED register value into step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 394 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 395 | * @param Speed The SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 396 | * @retval step/s The speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 397 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 398 | float L6470::L6470_Speed_2_Step_s(uint32_t Speed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 399 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 400 | return (Speed * ((float)14.9012e-3)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 401 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 402 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 403 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 404 | * @brief Convert the speed as step/s into a right value for SPEED register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 405 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 406 | * @param step/s The speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 407 | * @retval Speed The SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 408 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 409 | uint32_t L6470::L6470_Step_s_2_Speed(float Step_s) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 410 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 411 | if (Step_s <= (L6470_MAX_SPEED * ((float)14.9012e-3))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 412 | return (uint32_t)(Step_s / ((float)14.9012e-3)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 413 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 414 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 415 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 416 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 417 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 418 | * @brief Convert the ACC register value into step/(s^2). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 419 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 420 | * @param Acc The ACC register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 421 | * @retval step/(s^2) The acceleration as step/(s^2). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 422 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 423 | float L6470::L6470_Acc_2_Step_s2(uint16_t Acc) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 424 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 425 | if (Acc <= L6470_MAX_ACC) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 426 | return (Acc * ((float)1.4552e1)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 427 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 428 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 429 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 430 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 431 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 432 | * @brief Convert the acceleartion as step/(s^2) into a right value for ACC register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 433 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 434 | * @param step/(s^2) The acceleration as step/(s^2). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 435 | * @retval Acc The ACC register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 436 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 437 | uint16_t L6470::L6470_Step_s2_2_Acc(float Step_s2) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 438 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 439 | if (Step_s2 <= (L6470_MAX_ACC * ((float)1.4552e1))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 440 | return (uint16_t)(Step_s2 / ((float)1.4552e1)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 441 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 442 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 443 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 444 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 445 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 446 | * @brief Convert the DEC register value into step/(s^2). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 447 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 448 | * @param Dec The DEC register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 449 | * @retval step/(s^2) The deceleration as step/(s^2). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 450 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 451 | float L6470::L6470_Dec_2_Step_s2(uint16_t Dec) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 452 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 453 | if (Dec <= L6470_MAX_DEC) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 454 | return (Dec * ((float)1.4552e1)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 455 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 456 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 457 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 458 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 459 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 460 | * @brief Convert the deceleration as step/(s^2) into a right value for DEC register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 461 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 462 | * @param step/(s^2) The deceleration as step/(s^2). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 463 | * @retval Dec The DEC register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 464 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 465 | uint16_t L6470::L6470_Step_s2_2_Dec(float Step_s2) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 466 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 467 | if (Step_s2 <= (L6470_MAX_DEC * ((float)1.4552e1))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 468 | return (uint16_t)(Step_s2 / ((float)1.4552e1)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 469 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 470 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 471 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 472 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 473 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 474 | * @brief Convert the MAX_SPEED register value into step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 475 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 476 | * @param MaxSpeed The MAX_SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 477 | * @retval step/s The max speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 478 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 479 | float L6470::L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 480 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 481 | if (MaxSpeed <= L6470_MAX_MAX_SPEED) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 482 | return (MaxSpeed * ((float)15.2588)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 483 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 484 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 485 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 486 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 487 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 488 | * @brief Convert the max speed as step/s into a right value for MAX_SPEED register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 489 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 490 | * @param step/s The max speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 491 | * @retval MaxSpeed The MAX_SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 492 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 493 | uint16_t L6470::L6470_Step_s_2_MaxSpeed(float Step_s) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 494 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 495 | if (Step_s <= (L6470_MAX_MAX_SPEED * ((float)15.2588))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 496 | return (uint16_t)(Step_s / ((float)15.2588)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 497 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 498 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 499 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 500 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 501 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 502 | * @brief Convert the MIN_SPEED register value into step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 503 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 504 | * @param MinSpeed The MIN_SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 505 | * @retval step/s The min speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 506 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 507 | float L6470::L6470_MinSpeed_2_Step_s(uint16_t MinSpeed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 508 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 509 | if (MinSpeed <= L6470_MAX_MIN_SPEED) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 510 | return (MinSpeed * ((float)238.4186e-3)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 511 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 512 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 513 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 514 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 515 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 516 | * @brief Convert the min speed as step/s into a right value for MIN_SPEED register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 517 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 518 | * @param step/s The min speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 519 | * @retval MinSpeed The MIN_SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 520 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 521 | uint16_t L6470::L6470_Step_s_2_MinSpeed(float Step_s) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 522 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 523 | if (Step_s <= (L6470_MAX_MIN_SPEED * ((float)238.4186e-3))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 524 | return (uint16_t)(Step_s / ((float)238.4186e-3)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 525 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 526 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 527 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 528 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 529 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 530 | * @brief Convert the FS_SPD register value into step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 531 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 532 | * @param FsSpd The FS_SPD register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 533 | * @retval step/s The full-step speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 534 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 535 | float L6470::L6470_FsSpd_2_Step_s(uint16_t FsSpd) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 536 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 537 | if (FsSpd <= L6470_MAX_FS_SPD) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 538 | return ((FsSpd+0.5) * ((float)15.25)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 539 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 540 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 541 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 542 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 543 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 544 | * @brief Convert the full-step speed as step/s into a right value for FS_SPD register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 545 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 546 | * @param step/s The full-step speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 547 | * @retval FsSpd The FS_SPD register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 548 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 549 | uint16_t L6470::L6470_Step_s_2_FsSpd(float Step_s) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 550 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 551 | if (Step_s <= ((L6470_MAX_FS_SPD+0.5) * ((float)15.25))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 552 | return (uint16_t)((float)(Step_s / ((float)15.25)) - (float)0.5); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 553 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 554 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 555 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 556 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 557 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 558 | * @brief Convert the INT_SPEED register value into step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 559 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 560 | * @param IntSpeed The INT_SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 561 | * @retval step/s The intersect speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 562 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 563 | float L6470::L6470_IntSpeed_2_Step_s(uint16_t IntSpeed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 564 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 565 | if (IntSpeed <= L6470_MAX_INT_SPEED) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 566 | return (IntSpeed * ((float)59.6046e-3)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 567 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 568 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 569 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 570 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 571 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 572 | * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 573 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 574 | * @param step/s The full-step speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 575 | * @retval FsSpd The FS_SPD register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 576 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 577 | uint16_t L6470::L6470_Step_s_2_IntSpeed(float Step_s) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 578 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 579 | if (Step_s <= (L6470_MAX_INT_SPEED * ((float)59.6046e-3))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 580 | return (uint16_t)(Step_s / ((float)59.6046e-3)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 581 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 582 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 583 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 584 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 585 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 586 | * @brief Convert the ST_SLP register value into s/step. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 587 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 588 | * @param StartSlope The ST_SLP register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 589 | * @retval s/step The start slope as s/step. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 590 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 591 | float L6470::L6470_StSlp_2_s_Step(uint8_t StSlp) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 592 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 593 | // if (StSlp <= L6470_MAX_ST_SLP) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 594 | return (StSlp * ((float)1.5686e-5)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 595 | // else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 596 | // return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 597 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 598 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 599 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 600 | * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 601 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 602 | * @param step/s The full-step speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 603 | * @retval FsSpd The FS_SPD register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 604 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 605 | uint8_t L6470::L6470_s_Step_2_StSlp(float s_Step) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 606 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 607 | if (s_Step <= (L6470_MAX_ST_SLP * ((float)1.5686e-5))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 608 | return (uint8_t)(s_Step / ((float)1.5686e-5)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 609 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 610 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 611 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 612 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 613 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 614 | * @brief Convert the INT_SPEED register value into step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 615 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 616 | * @param IntSpeed The INT_SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 617 | * @retval step/s The intersect speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 618 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 619 | float L6470::L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 620 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 621 | // if (FnSlpAcc <= L6470_MAX_FN_SLP_ACC) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 622 | return (FnSlpAcc * ((float)1.5686e-5)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 623 | // else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 624 | // return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 625 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 626 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 627 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 628 | * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 629 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 630 | * @param step/s The full-step speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 631 | * @retval FsSpd The FS_SPD register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 632 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 633 | uint8_t L6470::L6470_s_Step_2_FnSlpAcc(float s_Step) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 634 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 635 | if (s_Step <= (L6470_MAX_FN_SLP_ACC * ((float)1.5686e-5))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 636 | return (uint8_t)(s_Step / ((float)1.5686e-5)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 637 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 638 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 639 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 640 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 641 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 642 | * @brief Convert the INT_SPEED register value into step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 643 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 644 | * @param IntSpeed The INT_SPEED register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 645 | * @retval step/s The intersect speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 646 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 647 | float L6470::L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 648 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 649 | // if (FnSlpDec <= L6470_MAX_FN_SLP_DEC) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 650 | return (FnSlpDec * ((float)1.5686e-5)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 651 | // else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 652 | // return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 653 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 654 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 655 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 656 | * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 657 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 658 | * @param step/s The full-step speed as step/s. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 659 | * @retval FsSpd The FS_SPD register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 660 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 661 | uint8_t L6470::L6470_s_Step_2_FnSlpDec(float s_Step) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 662 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 663 | if (s_Step <= (L6470_MAX_FN_SLP_DEC * ((float)1.5686e-5))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 664 | return (uint8_t)(s_Step / ((float)1.5686e-5)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 665 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 666 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 667 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 668 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 669 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 670 | * @brief Convert the OCD_TH register value into mA. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 671 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 672 | * @param OcdTh The OCD_TH register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 673 | * @retval mA The overcurrent threshold as mA. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 674 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 675 | float L6470::L6470_OcdTh_2_mA(uint8_t OcdTh) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 676 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 677 | if (OcdTh <= L6470_MAX_OCD_TH) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 678 | return ((OcdTh+1) * ((float)375)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 679 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 680 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 681 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 682 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 683 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 684 | * @brief Convert the overcurrent threshold as mA into a right value for OCD_TH register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 685 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 686 | * @param mA The overcurrent threshold as mA. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 687 | * @retval OcdTh The OCD_TH register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 688 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 689 | uint8_t L6470::L6470_mA_2_OcdTh(float mA) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 690 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 691 | float result, decimal; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 692 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 693 | if (mA <= ((L6470_MAX_OCD_TH+1) * ((float)375))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 694 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 695 | result = (mA / ((float)375)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 696 | decimal = result - (uint8_t)result; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 697 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 698 | if (decimal < (float)0.5) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 699 | return ((uint8_t)result - 1); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 700 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 701 | return ((uint8_t)result); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 702 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 703 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 704 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 705 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 706 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 707 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 708 | * @brief Convert the STALL_TH register value into mA. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 709 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 710 | * @param StallTh The STALL_TH register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 711 | * @retval mA The stall detection threshold as mA. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 712 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 713 | float L6470::L6470_StallTh_2_mA(uint8_t StallTh) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 714 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 715 | if (StallTh <= L6470_MAX_STALL_TH) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 716 | return ((StallTh+1) * ((float)31.25)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 717 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 718 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 719 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 720 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 721 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 722 | * @brief Convert the stall detection threshold as mA into a right value for STALL_TH register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 723 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 724 | * @param mA The stall detection threshold as mA. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 725 | * @retval StallTh The STALL_TH register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 726 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 727 | uint8_t L6470::L6470_mA_2_StallTh(float mA) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 728 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 729 | float result, decimal; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 730 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 731 | if (mA <= ((L6470_MAX_STALL_TH+1) * ((float)31.25))) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 732 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 733 | result = (mA / ((float)31.25)); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 734 | decimal = result - (uint8_t)result; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 735 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 736 | if (decimal < (float)0.5) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 737 | return ((uint8_t)result - 1); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 738 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 739 | return ((uint8_t)result); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 740 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 741 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 742 | return 0; // Warning |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 743 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 744 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 745 | /* End of L6470_Conversion_Functions */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 746 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 747 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 748 | * @addtogroup L6470_AppCMDs |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 749 | * @{ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 750 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 751 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 752 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 753 | * @brief SetParam command sets the register value equal to a new value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 754 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 755 | * @param L6470_RegId The identifier of the L6470 register to be addressed. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 756 | * @param Value The new value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 757 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 758 | void L6470::L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 759 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 760 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 761 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 762 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 763 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 764 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 765 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 766 | * @brief GetParam command reads the register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 767 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 768 | * @param L6470_RegId The identifier of the L6470 register to be addressed. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 769 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 770 | * @retval ReceivedValue The register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 771 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 772 | uint32_t L6470::L6470_GetParam(eL6470_RegId_t L6470_RegId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 773 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 774 | uint8_t ValueLengthByte; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 775 | uint32_t ReceivedValue; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 776 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 777 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 778 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 779 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 780 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 781 | ValueLengthByte = L6470_Register[L6470_RegId].LengthByte; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 782 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 783 | ReceivedValue = L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, ValueLengthByte); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 784 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 785 | return ReceivedValue; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 786 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 787 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 788 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 789 | * @brief Run command produces a motion at fixed speed. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 790 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 791 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 792 | * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 793 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 794 | void L6470::L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 795 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 796 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 797 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 798 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 799 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 800 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 801 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 802 | * @brief StepClock command switches the device in Step-clock mode. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 803 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 804 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 805 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 806 | void L6470::L6470_StepClock(eL6470_DirId_t L6470_DirId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 807 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 808 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 809 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 810 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 811 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 812 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 813 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 814 | * @brief Move command produces a motion of N_STEP microsteps. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 815 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 816 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 817 | * @param N_Step The number of microsteps. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 818 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 819 | void L6470::L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 820 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 821 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 822 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 823 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 824 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 825 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 826 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 827 | * @brief GoTo command produces a motion to ABS_POS absolute position through the shortest path. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 828 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 829 | * @param AbsPos The target absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 830 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 831 | void L6470::L6470_GoTo(uint32_t AbsPos) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 832 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 833 | if (AbsPos <= L6470_POSITION_RANGE) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 834 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 835 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 836 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 837 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 838 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 839 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 840 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 841 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 842 | * @brief GoTo_DIR command produces a motion to ABS_POS absolute position imposing a direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 843 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 844 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 845 | * @param AbsPos The target absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 846 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 847 | void L6470::L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 848 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 849 | if (AbsPos <= L6470_POSITION_RANGE) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 850 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 851 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 852 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 853 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 854 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 855 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 856 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 857 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 858 | * @brief GoUntil command produces a motion at fixed speed imposing a direction |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 859 | * until an external switch turn-on event occurs. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 860 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 861 | * @param L6470_ActId The identifier of the L6470 action about the absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 862 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 863 | * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 864 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 865 | void L6470::L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 866 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 867 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 868 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 869 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 870 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 871 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 872 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 873 | * @brief ReleaseSW command produces a motion at minimum speed imposing a direction |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 874 | * until SW is released. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 875 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 876 | * @param L6470_ActId The identifier of the L6470 action about the absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 877 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 878 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 879 | void L6470::L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 880 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 881 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 882 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 883 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 884 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 885 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 886 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 887 | * @brief GoHome command produces a motion to the HOME position (zero position) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 888 | * via the shortest path. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 889 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 890 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 891 | void L6470::L6470_GoHome(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 892 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 893 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 894 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 895 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 896 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 897 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 898 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 899 | * @brief GoMark command produces a motion to the MARK position performing the |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 900 | * minimum path. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 901 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 902 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 903 | void L6470::L6470_GoMark(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 904 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 905 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 906 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 907 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 908 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 909 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 910 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 911 | * @brief ResetPos command resets the ABS_POS register to zero. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 912 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 913 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 914 | void L6470::L6470_ResetPos(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 915 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 916 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 917 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 918 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 919 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 920 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 921 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 922 | * @brief ResetDevice command resets the device to power-up conditions. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 923 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 924 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 925 | void L6470::L6470_ResetDevice(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 926 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 927 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 928 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 929 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 930 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 931 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 932 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 933 | * @brief SoftStop command causes an immediate deceleration to zero speed and |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 934 | * a consequent motor stop; the deceleration value used is the one stored |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 935 | * in the DEC register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 936 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 937 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 938 | void L6470::L6470_SoftStop(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 939 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 940 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 941 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 942 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 943 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 944 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 945 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 946 | * @brief HardStop command causes an immediate motor stop with infinite deceleration. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 947 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 948 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 949 | void L6470::L6470_HardStop(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 950 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 951 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 952 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 953 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 954 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 955 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 956 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 957 | * @brief SoftHiZ command disables the power bridges (high impedance state) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 958 | * after a deceleration to zero; the deceleration value used is the one |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 959 | * stored in the DEC register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 960 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 961 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 962 | void L6470::L6470_SoftHiZ(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 963 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 964 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 965 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 966 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 967 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 968 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 969 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 970 | * @brief HardHiZ command immediately disables the power bridges (high impedance state). |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 971 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 972 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 973 | void L6470::L6470_HardHiZ(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 974 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 975 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 976 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 977 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 978 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 979 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 980 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 981 | * @brief GetStatus command returns the STATUS register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 982 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 983 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 984 | * @retval ReceivedValue The register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 985 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 986 | uint16_t L6470::L6470_GetStatus(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 987 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 988 | uint16_t ReceivedValue; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 989 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 990 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 991 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 992 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 993 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 994 | ReceivedValue = (uint16_t)L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, 2); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 995 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 996 | return ReceivedValue; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 997 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 998 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 999 | /* End of L6470_AppCMDs */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1000 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1001 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1002 | * @addtogroup L6470_AppCMDs_ToBePrepared |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1003 | * @{ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1004 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1005 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1006 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1007 | * @brief Prepare to send @ref L6470_SetParam command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1008 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1009 | * @param L6470_RegId The identifier of the L6470 register to be addressed. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1010 | * @param Value The new value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1011 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1012 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1013 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1014 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1015 | void L6470::L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1016 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1017 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1018 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1019 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1020 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1021 | * @brief Prepare to send @ref L6470_GetParam command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1022 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1023 | * @param L6470_Id The L6470 identifier inside the daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1024 | * @param L6470_RegId The identifier of the L6470 register to be addressed. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1025 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1026 | * @retval ReceivedValue The register value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1027 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1028 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1029 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1030 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1031 | void L6470::L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1032 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1033 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1034 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1035 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1036 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1037 | * @brief Prepare to send @ref L6470_Run command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1038 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1039 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1040 | * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1041 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1042 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1043 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1044 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1045 | void L6470::L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1046 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1047 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1048 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1049 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1050 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1051 | * @brief Prepare to send @ref L6470_StepClock command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1052 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1053 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1054 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1055 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1056 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1057 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1058 | void L6470::L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1059 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1060 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1061 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1062 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1063 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1064 | * @brief Prepare to send @ref L6470_Move command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1065 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1066 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1067 | * @param N_Step The number of microsteps. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1068 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1069 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1070 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1071 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1072 | void L6470::L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1073 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1074 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1075 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1076 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1077 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1078 | * @brief Prepare to send @ref L6470_GoTo command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1079 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1080 | * @param AbsPos The target absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1081 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1082 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1083 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1084 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1085 | void L6470::L6470_PrepareGoTo(uint32_t AbsPos) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1086 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1087 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1088 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1089 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1090 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1091 | * @brief Prepare to send @ref L6470_GoToDIR command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1092 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1093 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1094 | * @param AbsPos The target absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1095 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1096 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1097 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1098 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1099 | void L6470::L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1100 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1101 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1102 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1103 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1104 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1105 | * @brief Prepare to send @ref L6470_GoUntil command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1106 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1107 | * @param L6470_ActId The identifier of the L6470 action about the absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1108 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1109 | * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1110 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1111 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1112 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1113 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1114 | void L6470::L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1115 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1116 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1117 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1118 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1119 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1120 | * @brief Prepare to send @ref L6470_ReleaseSW. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1121 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1122 | * @param L6470_ActId The identifier of the L6470 action about the absolute position. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1123 | * @param L6470_DirId The identifier of the L6470 motion direction. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1124 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1125 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1126 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1127 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1128 | void L6470::L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1129 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1130 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1131 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1132 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1133 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1134 | * @brief Prepare to send @ref L6470_GoHome command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1135 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1136 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1137 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1138 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1139 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1140 | void L6470::L6470_PrepareGoHome(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1141 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1142 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1143 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1144 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1145 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1146 | * @brief Prepare to send @ref L6470_GoMark command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1147 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1148 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1149 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1150 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1151 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1152 | void L6470::L6470_PrepareGoMark(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1153 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1154 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1155 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1156 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1157 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1158 | * @brief Prepare to send @ref L6470_ResetPos command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1159 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1160 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1161 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1162 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1163 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1164 | void L6470::L6470_PrepareResetPos(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1165 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1166 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1167 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1168 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1169 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1170 | * @brief Prepare to send @ref L6470_ResetDevice command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1171 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1172 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1173 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1174 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1175 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1176 | void L6470::L6470_PrepareResetDevice(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1177 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1178 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1179 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1180 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1181 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1182 | * @brief Prepare to send @ref L6470_SoftStop command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1183 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1184 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1185 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1186 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1187 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1188 | void L6470::L6470_PrepareSoftStop(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1189 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1190 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1191 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1192 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1193 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1194 | * @brief Prepare to send @ref L6470_HardStop command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1195 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1196 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1197 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1198 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1199 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1200 | void L6470::L6470_PrepareHardStop(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1201 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1202 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1203 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1204 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1205 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1206 | * @brief Prepare to send @ref L6470_SoftHiZ command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1207 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1208 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1209 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1210 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1211 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1212 | void L6470::L6470_PrepareSoftHiZ(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1213 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1214 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1215 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1216 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1217 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1218 | * @brief Prepare to send @ref L6470_HardHiZ command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1219 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1220 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1221 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1222 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1223 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1224 | void L6470::L6470_PrepareHardHiZ(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1225 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1226 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1227 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1228 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1229 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1230 | * @brief Prepare to send @ref L6470_GetStatus command. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1231 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1232 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1233 | * @note This function will properly fill the right column of the L6470_AppCmdPkg. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1234 | * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1235 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1236 | void L6470::L6470_PrepareGetStatus(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1237 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1238 | L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1239 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1240 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1241 | /* End of L6470_AppCMDs_ToBePrepared */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1242 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1243 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1244 | * @brief Send via SPI the command stored inside the L6470_AppCmdPkg to the |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1245 | * L6470 daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1246 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1247 | * @retval (uint8_t*)data->L6470_DaisyChainSpiRxStruct The pointer to the structure |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1248 | * containing returned values from each L6470 of the daisy chain for each |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1249 | * sent SPI data. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1250 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1251 | uint8_t* L6470::L6470_PerformPreparedApplicationCommand(void) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1252 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1253 | L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1254 | L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1255 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1256 | return (uint8_t*)(L6470_DaisyChainSpiRxStruct); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1257 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1258 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1259 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1260 | * @brief Send command to the L6470 daisy chain via SPI |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1261 | * @param pL6470_DaisyChainSpiTxStruct Pointer to the matrix array of bytes to be sent to the daisy chain L6470 |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1262 | * @param pL6470_DaisyChainSpiRxStruct Pointer to the matrix array of bytes to be received from the daisy chain L6470 |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1263 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1264 | void L6470::L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1265 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1266 | uint8_t spibyte; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1267 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1268 | L6470_DaisyChain_HalfPrepared = ZERO_F; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1269 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1270 | /* Send all command bytes via SPI */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1271 | for(spibyte=0; spibyte < L6470MAXSPICMDBYTESIZE; spibyte++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1272 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1273 | /* Send the command via SPI */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1274 | L6470_SPI_Communication((pL6470_DaisyChainSpiTxStruct+(spibyte * L6470DAISYCHAINSIZE)), (pL6470_DaisyChainSpiRxStruct+(spibyte * L6470DAISYCHAINSIZE)), L6470DAISYCHAINSIZE, 10); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1275 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1276 | //_DELAY(TDISCS); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1277 | uint8_t delay_cnt; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1278 | for (delay_cnt=0; delay_cnt<20; delay_cnt++) __NOP(); //!<Simply deselect time delay for SPI nCS |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1279 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1280 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1281 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1282 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1283 | * @brief Extracts the data returned by the L6470 from the matrix that |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1284 | * contains the received SPI data. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1285 | * @param L6470_Id The identifier of the L6470 target inside the daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1286 | * @param pL6470_DaisyChainSpiRxStruct uint8_t-pointer to the matrix that |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1287 | * contains the received data by SPI from the L6470 daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1288 | * @param LengthByte The number of bytes about the received value. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1289 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1290 | uint32_t L6470::L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1291 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1292 | uint32_t value; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1293 | uint8_t i; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1294 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1295 | value = 0x000000; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1296 | for (i=1; i<=(L6470MAXSPICMDBYTESIZE-1); i++) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1297 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1298 | value |= (*(pL6470_DaisyChainSpiRxStruct+(i*L6470DAISYCHAINSIZE)+L6470_Id))<<((LengthByte-i)*8); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1299 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1300 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1301 | return value; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1302 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1303 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1304 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1305 | * @brief Check the state of a flag inside the L6470 STATUS register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1306 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1307 | * @param L6470_Id The identifier of the L6470 target inside the daisy chain. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1308 | * @param L6470_StatusRegisterFlagId The identifier of the L6470 STATUS flag to be checked. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1309 | * |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1310 | * @retval state The flag state. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1311 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1312 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1313 | uint8_t L6470::L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1314 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1315 | uint8_t state = 0; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1316 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1317 | *((uint16_t*)pL6470_StatusRegister) = L6470_GetParam(L6470_STATUS_ID); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1318 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1319 | switch(L6470_StatusRegisterFlagId) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1320 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1321 | case HiZ_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1322 | state = pL6470_StatusRegister->HiZ; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1323 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1324 | case BUSY_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1325 | state = pL6470_StatusRegister->BUSY; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1326 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1327 | case SW_F_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1328 | state = pL6470_StatusRegister->SW_F; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1329 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1330 | case SW_EVN_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1331 | state = pL6470_StatusRegister->SW_EVN; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1332 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1333 | case DIR_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1334 | state = pL6470_StatusRegister->DIR; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1335 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1336 | case MOT_STATUS_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1337 | state = pL6470_StatusRegister->MOT_STATUS; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1338 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1339 | case NOTPERF_CMD_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1340 | state = pL6470_StatusRegister->NOTPERF_CMD; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1341 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1342 | case WRONG_CMD_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1343 | state = pL6470_StatusRegister->WRONG_CMD; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1344 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1345 | case UVLO_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1346 | state = pL6470_StatusRegister->UVLO; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1347 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1348 | case TH_WRN_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1349 | state = pL6470_StatusRegister->TH_WRN; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1350 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1351 | case TH_SD_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1352 | state = pL6470_StatusRegister->TH_SD; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1353 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1354 | case OCD_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1355 | state = pL6470_StatusRegister->OCD; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1356 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1357 | case STEP_LOSS_A_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1358 | state = pL6470_StatusRegister->STEP_LOSS_A; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1359 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1360 | case STEP_LOSS_B_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1361 | state = pL6470_StatusRegister->STEP_LOSS_B; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1362 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1363 | case SCK_MOD_ID: |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1364 | state = pL6470_StatusRegister->SCK_MOD; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1365 | break; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1366 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1367 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1368 | return state; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1369 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1370 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1371 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1372 | * @brief Return the mnemonic name for the L6470 register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1373 | * @param id The identifier of the L6470 register. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1374 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1375 | uint8_t *L6470::L6470_GetRegisterName(uint8_t id) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1376 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1377 | if (id < L6470REGIDSIZE) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1378 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1379 | return (uint8_t*)L6470_Register[id].Name; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1380 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1381 | else |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1382 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1383 | return NULL; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1384 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1385 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1386 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1387 | /** |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1388 | * @brief Configures the L6470 registers. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1389 | * @param init The pointer to the initialization structure. |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1390 | */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1391 | status_t L6470::L6470_Config(void *init) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1392 | { |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1393 | /* Disable the L6470. */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1394 | L6470_DISABLE(); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1395 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1396 | /* Enable the L6470. */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1397 | L6470_ENABLE(); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1398 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1399 | /* Reset devices. */ |
Davidroid | 23:cf489f2ab072 | 1400 | reset_device(); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1401 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1402 | /* Reset Status Register flags. */ |
Davidroid | 23:cf489f2ab072 | 1403 | get_status(); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1404 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1405 | /* Prepare the 'Register' field of StepperMotorDriverHandle */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1406 | L6470_init_t *MotorParameterData = (L6470_init_t *) init; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1407 | StepperMotorRegister.ACC = L6470_Step_s2_2_Acc(MotorParameterData->acc); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1408 | StepperMotorRegister.DEC = L6470_Step_s2_2_Dec(MotorParameterData->dec); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1409 | StepperMotorRegister.MAX_SPEED = L6470_Step_s_2_MaxSpeed(MotorParameterData->maxspeed); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1410 | StepperMotorRegister.MIN_SPEED = L6470_Step_s_2_MinSpeed(MotorParameterData->minspeed); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1411 | StepperMotorRegister.FS_SPD = L6470_Step_s_2_FsSpd(MotorParameterData->fsspd); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1412 | StepperMotorRegister.KVAL_HOLD = (uint8_t)((float)((float)(MotorParameterData->kvalhold * 256) / (MotorParameterData->motorvoltage))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1413 | StepperMotorRegister.KVAL_RUN = (uint8_t)((float)((float)(MotorParameterData->kvalrun * 256) / (MotorParameterData->motorvoltage))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1414 | StepperMotorRegister.KVAL_ACC = (uint8_t)((float)((float)(MotorParameterData->kvalacc * 256) / (MotorParameterData->motorvoltage))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1415 | StepperMotorRegister.KVAL_DEC = (uint8_t)((float)((float)(MotorParameterData->kvaldec * 256) / (MotorParameterData->motorvoltage))); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1416 | StepperMotorRegister.INT_SPEED = L6470_Step_s_2_IntSpeed(MotorParameterData->intspeed); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1417 | StepperMotorRegister.ST_SLP = L6470_s_Step_2_StSlp(MotorParameterData->stslp); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1418 | StepperMotorRegister.FN_SLP_ACC = L6470_s_Step_2_FnSlpAcc(MotorParameterData->fnslpacc); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1419 | StepperMotorRegister.FN_SLP_DEC = L6470_s_Step_2_FnSlpDec(MotorParameterData->fnslpdec); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1420 | StepperMotorRegister.K_THERM = MotorParameterData->kterm; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1421 | StepperMotorRegister.OCD_TH = L6470_mA_2_OcdTh(MotorParameterData->ocdth); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1422 | StepperMotorRegister.STALL_TH = L6470_mA_2_StallTh(MotorParameterData->stallth); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1423 | StepperMotorRegister.ALARM_EN = MotorParameterData->alarmen; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1424 | StepperMotorRegister.CONFIG = MotorParameterData->config; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1425 | StepperMotorRegister.STEP_MODE = MotorParameterData->step_sel; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1426 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1427 | /* Write the L6470 registers with the prepared data */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1428 | L6470_SetParam(L6470_ACC_ID, StepperMotorRegister.ACC); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1429 | L6470_SetParam(L6470_DEC_ID, StepperMotorRegister.DEC); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1430 | L6470_SetParam(L6470_MAX_SPEED_ID, StepperMotorRegister.MAX_SPEED); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1431 | L6470_SetParam(L6470_MIN_SPEED_ID, StepperMotorRegister.MIN_SPEED); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1432 | L6470_SetParam(L6470_FS_SPD_ID, StepperMotorRegister.FS_SPD); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1433 | L6470_SetParam(L6470_KVAL_HOLD_ID, StepperMotorRegister.KVAL_HOLD); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1434 | L6470_SetParam(L6470_KVAL_RUN_ID, StepperMotorRegister.KVAL_RUN); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1435 | L6470_SetParam(L6470_KVAL_ACC_ID, StepperMotorRegister.KVAL_ACC); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1436 | L6470_SetParam(L6470_KVAL_DEC_ID, StepperMotorRegister.KVAL_DEC); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1437 | L6470_SetParam(L6470_INT_SPEED_ID, StepperMotorRegister.INT_SPEED); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1438 | L6470_SetParam(L6470_ST_SLP_ID, StepperMotorRegister.ST_SLP); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1439 | L6470_SetParam(L6470_FN_SLP_ACC_ID, StepperMotorRegister.FN_SLP_ACC); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1440 | L6470_SetParam(L6470_FN_SLP_DEC_ID, StepperMotorRegister.FN_SLP_DEC); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1441 | L6470_SetParam(L6470_K_THERM_ID, StepperMotorRegister.K_THERM); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1442 | L6470_SetParam(L6470_OCD_TH_ID, StepperMotorRegister.OCD_TH); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1443 | L6470_SetParam(L6470_STALL_TH_ID, StepperMotorRegister.STALL_TH); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1444 | L6470_SetParam(L6470_ALARM_EN_ID, StepperMotorRegister.ALARM_EN); |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1445 | L6470_SetParam(L6470_CONFIG_ID, StepperMotorRegister.CONFIG); |
Davidroid | 23:cf489f2ab072 | 1446 | if (!set_step_mode((StepperMotor::step_mode_t) StepperMotorRegister.STEP_MODE)) |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1447 | return COMPONENT_ERROR; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1448 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1449 | return COMPONENT_OK; |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1450 | } |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1451 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1452 | /* End of L6470_Exported_Functions */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1453 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1454 | /* End of L6470 */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1455 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1456 | /* End of Components */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1457 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1458 | /* End of BSP */ |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1459 | |
davide.aliprandi@st.com | 22:ba7f4131a5e0 | 1460 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |